Forum Moderators: coopster

Message Too Old, No Replies

Help w/ PHP query

PHP Query

         

terk

5:02 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



Hello..

here is my problem im learning php and im having problems doing a simple query from mysql.. and i get this error

Call to a member function on a non-object in /nfs/cust/3/85/95/659583/web/php/TMP44bo8vpfyi.php on line 53

here's my code. please help me out :P

<?php
$q= mysql_query ('SELECT name FROM items');
while ($row = $q -> mysql_fetc_array ()) {
print "$row[0], $row[1] \n";
?>

Robber

5:27 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



Just a typo:

while ($row = $q -> mysql_fetc_array ()) {

should be:

while ($row = $q -> mysql_fetch_array ()) {

inveni0

5:29 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



There seems to be a few things missing from your code. Try:

<?php

$q = mysql_query("SELECT name FROM items AS row");
$ShowQuery = mysql_fetch_array($q);
print_r($ShowQuery['row']);

?>

This isn't what you're trying to do, but it should allow you to see if you can query your DB successfully.

terk

6:01 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



thanks inveni0... i dont get an error anymore but for some reason i cant see the listing from mysql.. (im new to programin :P )

coopster

6:19 pm on Mar 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hi terk and welcome to WebmasterWorld.

You need to make a connection to the database first. There is a nice example in our PHP Forum Library [webmasterworld.com] that describes the Basics of extracting data from MySQL [webmasterworld.com] that you might want to read through.

terk

8:48 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



ihave to admit im a PHP noob :P i connect to mysql with no problem i can do a simple query to my db... but i want to display my information on a table, i have 5 rows
NAME, SKU, WAREHOUSE, CATEGORY, DESCRIPTION

$q= mysql_query ("SELECT * FROM items ");
$showquery = mysql_fetch_array($q);
while ($row = $showquery){$row = mysql_fetch_assoc($q);
print $row['name'] ;}

jatar_k

9:18 pm on Mar 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you have your syntax a bit whacky

try this thread for the basics

Basics of extracting data from MySQL using PHP [webmasterworld.com]

<added>oops, coopster already mentioned it, have a look it will show you exactly the thing you are having problems with