|
-
March 11th, 2010, 12:56 PM
#1
I've done the searching
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:
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.
-
March 11th, 2010, 12:57 PM
#2
Re: I've done the searching
Forgot to mention I'm using SQL 4.1 if that matters.
-
March 11th, 2010, 01:28 PM
#3
Re: I've done the searching
I believe it doesn't like the I think this is used in classes wich are objects, and your code is not object oriented. what is your goal? Somethng like this?
Code:
<?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";
}
?>
Last edited by bobo; March 11th, 2010 at 01:37 PM.
-
March 11th, 2010, 01:34 PM
#4
Re: I've done the searching
 Originally Posted by bobo
I believe it doesn't like the 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.
-
March 11th, 2010, 01:36 PM
#5
Re: I've done the searching
oops we submitted at the same time, look above, just echo your TRs and TDs where I got my echo
Last edited by bobo; March 11th, 2010 at 01:38 PM.
-
March 11th, 2010, 01:40 PM
#6
Re: I've done the searching
I'll try to plug that in and see what happens. Thanks. I'll reply the results.
-
March 11th, 2010, 01:43 PM
#7
Re: I've done the searching
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.
Code:
<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>
Last edited by bobo; March 11th, 2010 at 01:54 PM.
-
March 11th, 2010, 01:54 PM
#8
Re: I've done the searching
You nailed it. By removing $db-> and replacing with mysql_query all problems were resolved. Thanks!
-
March 11th, 2010, 01:57 PM
#9
Re: I've done the searching
your welcome
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|