Click to See Complete Forum and Search --> : I've done the searching
l3asturd
March 11th, 2010, 11:56 AM
I've searched and searched, and gotten many answers, but I can't solve this simple problem. I'm a rookie php/sql writer so please provide an example if the answer is more complicated than I think it is.
Here is my code:
<?php
$host = 10.0.0.1;
$user = 'user1';
$password = '*******';
$dbName = 'dbone';
$dbTable = 'tbone';
$conn = mysql_connect($host, $user, $password) or die(mysql_error());
$db = mysql_select_db($dbName, $conn) or die(mysql_error());
$select_resultx = $db->query_read("SELECT * FROM $dbTable", $conn);
and this is my result:
Call to a member function on a non-object ....pertaining to the $select_resultx line.
I've stripped it down to just SELECT *, removed all grouping and ordering, trying to isolate the problem. I am stuck on this basic script. :(
l3asturd
March 11th, 2010, 11:57 AM
Forgot to mention I'm using SQL 4.1 if that matters.
bobo
March 11th, 2010, 12:28 PM
I believe it doesn't like the $db-> I think this is used in classes wich are objects, and your code is not object oriented. what is your goal? Somethng like this?
<?php
$dbhost = 'localhost';
$dbname = 'dbname';
$dbUser = 'dbUser';
$dbPass = 'dbPass';
if (!@mysql_connect($dbhost,$dbUser,$dbPass) or !@mysql_select_db($dbname)){
echo "No database connection";
}
$query = "select column1, column2 from my table";
$Statement = mysql_query($query);
while($myid = mysql_fetch_array($Statement)) {
$column1 = $myid["column1"];
$column2 = $myid["column2"];
echo $column1."<br>\n";
echo $column2."<br>\n";
}
?>
l3asturd
March 11th, 2010, 12:34 PM
I believe it doesn't like the $db-> I think this is used in classes wich are objects, and your code is not object oriented. what is your goal?
Trying to extract table fields, group by 'name', then eventually display in a table.
bobo
March 11th, 2010, 12:36 PM
oops we submitted at the same time, look above, just echo your TRs and TDs where I got my echo
l3asturd
March 11th, 2010, 12:40 PM
I'll try to plug that in and see what happens. Thanks. I'll reply the results.
bobo
March 11th, 2010, 12:43 PM
here is a full example that I actually use on my local server. Excuse the french text
where you see the include of connection.php, you wont need that, this is the same connection stuff as above.
<table width="560" border="0" cellspacing="1" cellpadding="2">
<tr bgcolor="#c7c7c7">
<td width="160" align="center" class="reg_font">Nom</td>
<td width="180" align="center" class="reg_font">Courriel</td>
<td width="110" align="center" class="reg_font">Téléphone</td>
</tr>
<?php
include "connection.php";
$query = "select * from contacts where id != '3' order by lname";
$Statement = mysql_query($query);
while($myid = mysql_fetch_array($Statement)) {
$the_id = $myid["id"];
$last_name = $myid["lname"];
$first_name = $myid["fname"];
$email = $myid["e_address"];
$phonenum = $myid["phone"];
if($bg == "#ededf7"){
$bg = "#e7e7e7";
}else{
$bg = "#ededf7";
}
if(empty($phonenum)){
$phonenum = " ";
}
echo "<tr bgcolor=\"".$bg."\">\n";
echo "<td class=\"reg_font\">".$last_name.", ".$first_name."</td>\n";
echo "<td class=\"reg_font\"><a href=\"mailto:".$email."\" class=\"link_font\">".$email."</a></td>\n";
echo "<td class=\"reg_font\">".$phonenum."</td>\n";
echo "<tr>\n";
}
?>
</table>
l3asturd
March 11th, 2010, 12:54 PM
You nailed it. By removing $db-> and replacing with mysql_query all problems were resolved. Thanks!
bobo
March 11th, 2010, 12:57 PM
your welcome :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.