mysql error in php

Posted by fusion on Stack Overflow See other posts from Stack Overflow or by fusion
Published on 2010-04-07T16:21:29Z Indexed on 2010/04/07 16:33 UTC
Read the original article Hit count: 463

Filed under:
|
|
|
|

i'm trying to run this php code which should display a quote from mysql, but can't figure out where is it going wrong. the result variable is null or empty. can someone help me out. thanks!

<?php
include 'config.php';

// 'text' is the name of your table that contains
// the information you want to pull from
$rowcount = mysql_query("select count(*) as rows from quotes");

// Gets the total number of items pulled from database.
while ($row = mysql_fetch_assoc($rowcount))
{
$max = $row["rows"];
//print_r ($max);
}

// Selects an item's index at random 
$rand = rand(1,$max)-1;
print_r ($rand);
$result = mysql_query("select * from quotes limit $rand, 1") or die ('Error: '.mysql_error());
if (!$result or mysql_num_rows($result))
{
echo "Empty";
}
else{
while ($row = mysql_fetch_array($result)) {

$randomOutput = $row['cQuotes'];
echo '<p>' . $randomOutput . '</p>';
}
}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql