Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Oct 5, 2006, 23:01   #1
jmelwak
SitePoint Member
 
jmelwak's Avatar
 
Join Date: Oct 2006
Location: Las Vegas
Posts: 4
Question hello im new and need some help :(

hi all my name is john,
i have been doing html and flash for years now and want to get into the php and mysql side. I actually am waiting for my PHP book to arrive from sitepoint but i thought i would just jump in to try some things. I love the features it can add to your site. i am just starting out and have a database to display my data in rows and 4 columns. i got this code below and keep getting an error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hsphere/local/home/jmelwak/themusclecar.com/browse.php on line 40
can someone help me ? here is the code

<?php
//set the number of columns
$columns = 4;

mysql_connect('myhost,'myusername','mypassword');
mysql_select_db('mydatabase');
$query = "SELECT cartext FROM cars ORDER BY cars";
$result = mysql_query($query);

//we add this line because we need to know the number of rows
$num_rows = mysql_num_rows($result);
echo "<TABLE BORDER=\"0\">\n";

//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
$row = mysql_fetch_array($result);
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<TR>\n";
}
echo "<TD>" . $row['stuff'] . "</TD>\n";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
echo "</TR>\n";
}
}
echo "</TABLE>\n";
?>
jmelwak is offline   Reply With Quote
Old Oct 5, 2006, 23:07   #2
clamcrusher
SitePoint Wizard
silver trophy
 
Join Date: Mar 2006
Posts: 6,132
familiarize yourself with this function:
mysql_error()

see the manual for more info/usage examples. php.net/mysql_error
that should help you identify your problem.
clamcrusher is offline   Reply With Quote
Old Oct 5, 2006, 23:08   #3
jmelwak
SitePoint Member
 
jmelwak's Avatar
 
Join Date: Oct 2006
Location: Las Vegas
Posts: 4
ok thanks
jmelwak is offline   Reply With Quote
Old Oct 6, 2006, 05:58   #4
webnoob
SitePoint Wizard
 
webnoob's Avatar
 
Join Date: Dec 2004
Location: At My Desk!!
Posts: 1,643
PHP Code:

$result = mysql_query($query) or die (mysql_error()); 

will explain the error in more detail, but generally it means that the connection to the databse hasnt gone through properly and therefore the function you are calling is not valid. Make sure that your details are correct for connecting to the DB.
webnoob is offline   Reply With Quote
Old Oct 6, 2006, 08:15   #5
jmelwak
SitePoint Member
 
jmelwak's Avatar
 
Join Date: Oct 2006
Location: Las Vegas
Posts: 4
Quote:
Originally Posted by webnoob
PHP Code:

$result = mysql_query($query) or die (mysql_error()); 

will explain the error in more detail, but generally it means that the connection to the databse hasnt gone through properly and therefore the function you are calling is not valid. Make sure that your details are correct for connecting to the DB.
ohhhh, ok that helps me, i verified everything, im just lost here im now getting an error of Unknown column 'cars' in 'order clause', then when i change that 'cars' to 'cartext' it shows up no errors but blank, nothing?

Last edited by jmelwak; Oct 6, 2006 at 08:56.
jmelwak is offline   Reply With Quote
Old Oct 6, 2006, 10:02   #6
jmelwak
SitePoint Member
 
jmelwak's Avatar
 
Join Date: Oct 2006
Location: Las Vegas
Posts: 4
problem solved, thanks for all your help
jmelwak is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 18:43.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved