CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2010
    Posts
    6

    Exclamation 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.

  2. #2
    Join Date
    Mar 2010
    Posts
    6

    Re: I've done the searching

    Forgot to mention I'm using SQL 4.1 if that matters.

  3. #3
    Join Date
    Jun 2004
    Posts
    142

    Re: I've done the searching

    I believe it doesn't like the
    Code:
    $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?

    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.

  4. #4
    Join Date
    Mar 2010
    Posts
    6

    Re: I've done the searching

    Quote Originally Posted by bobo View Post
    I believe it doesn't like the
    Code:
    $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.

  5. #5
    Join Date
    Jun 2004
    Posts
    142

    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.

  6. #6
    Join Date
    Mar 2010
    Posts
    6

    Re: I've done the searching

    I'll try to plug that in and see what happens. Thanks. I'll reply the results.

  7. #7
    Join Date
    Jun 2004
    Posts
    142

    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&#233;l&#233;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 = "&nbsp;";
    	}
    	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.

  8. #8
    Join Date
    Mar 2010
    Posts
    6

    Re: I've done the searching

    You nailed it. By removing $db-> and replacing with mysql_query all problems were resolved. Thanks!

  9. #9
    Join Date
    Jun 2004
    Posts
    142

    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
  •  





Click Here to Expand Forum to Full Width

Featured