Page 2 of 3

Posted: Wed Jul 25, 2007 2:03 pm
by outdoorxtreme1
nothing at all.

Posted: Wed Jul 25, 2007 2:07 pm
by superdezign

Code: Select all

mysql_num_rows($result);
Maybe I should have been more specific.

Posted: Wed Jul 25, 2007 2:08 pm
by John Cartwright
you need to pass $result to mysql_num_rows()

Posted: Wed Jul 25, 2007 2:08 pm
by miro_igov
Totally wrong. Must be

Code: Select all

echo mysql_num_rows($result);
mysql_num_rows() requires argument, but if you say "Nothing at all" then your display_errors is disabled so this will make it hard to debug the script.

Posted: Wed Jul 25, 2007 2:12 pm
by outdoorxtreme1
Still nothing. Could the <1 in this line be wrong?

if(@mysql_num_rows($result)<1){

Posted: Wed Jul 25, 2007 2:15 pm
by miro_igov
Enable display_errors in your php.ini file or with ini_set(), looks like the issue is in the code. And remove any @ which suppress the error reporting.

Posted: Wed Jul 25, 2007 2:15 pm
by superdezign
I don't know what you're after, so I couldn't tell you.

And please... you are DEBUGGING the script. Stop using error suppression. You need all of the error messages you can get right now.

Posted: Wed Jul 25, 2007 2:20 pm
by outdoorxtreme1
I went thru and took all the error suppression out of the code. I forgot about the line I had it in. What I am looking to do is echo <a href=\"" . $row["link"] . "\">
<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>" selecting random rows from my database at a weekly time period.

Posted: Wed Jul 25, 2007 2:22 pm
by superdezign
Okay, that's fine and all, but our concern right now is the result of mysql_num_rows($result) right before the while loop.

Posted: Wed Jul 25, 2007 2:24 pm
by outdoorxtreme1
nothing on in the browser shows up. I view source code and nothing there either.

Posted: Wed Jul 25, 2007 2:28 pm
by superdezign
Turn on error reporting. $result can't possibly be a valid resource.

Also, run this before the while loop:

Code: Select all

if(!is_resource($result)) echo 'Invalid resource.';

Posted: Wed Jul 25, 2007 3:34 pm
by outdoorxtreme1
Error reporting is on and I still dont get an echo.

Current code:

Code: Select all

$today=date("w"); //current day of week: 0,1,2,3,4,5,6
$secs_so_far=mktime()-mktime(0,0,1); //seconds so far today
$days_before_today=$today;
if ($days_before_today>0)$secs_so_far+=$days_before_today*24*60*60; //if today isn't Sunday, add seconds for each day to the running total
$week_start=mktime()-($secs_so_far); //first second of week = (time now)-(seconds since the beginning) 

// Edit this number to however many links you want displaying
$num_displayed = 1 ;

// Select random rows from the database
$result = mysql_query ("SELECT * FROM links WHERE date='$week_start' ORDER BY RAND() LIMIT $num_displayed")or die ('Error: '.mysql_error ());

//if no links picked yet

if(mysql_num_rows($result)>1){

//redo the query, finding $num_displayed more rows without dates
$result = mysql_query ("SELECT * FROM links WHERE date='' ORDER BY RAND() LIMIT $num_displayed")or die ('Error: '.mysql_error ());

//update the 'date' field to match $week_start
$result = mysql_query ("UPDATE links SET date='$week_start' WHERE date='' LIMIT $num_displayed")or die ('Error: '.mysql_error ());

// Select random rows from the database
$result = mysql_query ("SELECT * FROM links WHERE date='$week_start' ORDER BY RAND() LIMIT $num_displayed")or die ('Error: '.mysql_error ());

if(!is_resource($result)) echo 'Invalid resource.';
echo mysql_num_rows($result);
//show the links that were just selected
while ($row = mysql_fetch_array($result)){
echo "<a href=\"" . $row["link"] . "\">
<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>" ;}
}

Posted: Wed Jul 25, 2007 3:39 pm
by superdezign
That's impossible.

Code: Select all

ini_set('display_errors', 1);
error_reporting(E_ALL);
The only way that could be possible is if you aren't even getting past your initial if statement.

Posted: Wed Jul 25, 2007 3:42 pm
by outdoorxtreme1
Every time I refresh there is nothing and the sorce code is blank also. Could there be another part of the code wrong?

Posted: Wed Jul 25, 2007 3:51 pm
by outdoorxtreme1
If I change this line

Code: Select all

if(mysql_num_rows($result)>1){


to this

Code: Select all

if(mysql_num_rows($result)){


then I get an echo but the pictures appear randomly each time the page is refreshed. What I am looking to do is Have the same picture for a week then after a week switch to another picture at random using the location of that picture from the database table.