|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Member
Join Date: Oct 2006
Location: Las Vegas
Posts: 4
|
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"; ?> |
|
|
|
|
|
#2 |
|
SitePoint Wizard
![]() 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. |
|
|
|
|
|
#3 |
|
SitePoint Member
Join Date: Oct 2006
Location: Las Vegas
Posts: 4
|
ok thanks
|
|
|
|
|
|
#4 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2004
Location: At My Desk!!
Posts: 1,643
|
PHP Code:
|
|
|
|
|
|
#5 | |
|
SitePoint Member
Join Date: Oct 2006
Location: Las Vegas
Posts: 4
|
Quote:
![]() Last edited by jmelwak; Oct 6, 2006 at 08:56. |
|
|
|
|
|
|
#6 |
|
SitePoint Member
Join Date: Oct 2006
Location: Las Vegas
Posts: 4
|
problem solved, thanks for all your help
![]() |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 18:43.











Linear Mode
