Page 1 of 1
Randomization code Help
Posted: Sun Aug 06, 2006 9:01 am
by jejimdude
I have attached a url with a zip file containing some php code which picks up random links feom my directory table, my articles table (another script), and my online bible (another script). But it displays many errors.Homepage:
IBelieve Christian Ministries
As you will see in my attachment index.php the first include dir.inc.php written for esyndicat displays properly as seen in:
http://www.ibelieve.uni.cc/random/index.php
But there is also a lot of errors I can't figure out why.
Please Help.
Attachement with code:
Randomlinks.zip
Posted: Sun Aug 06, 2006 9:13 am
by jayshields
You'd be better off just posting your code.
By the errors, I can guess that you're MySQL queries are returning < 2 records. You're trying to show row 1? That's the second returned row. If you think your queries will return one row, access row 0.
Try this on all your queries better debugging:
Code: Select all
mysql_query($query) or die('Cound not execute query: '.$query.'<br /><strong>'.mysql_error().'</strong>');
Posted: Sun Aug 06, 2006 9:17 am
by jejimdude
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
OK
[b]index.php[/b]
Code: Select all
<?
require 'dir.inc.php';
require 'bib.inc.php';
require 'art.inc.php';
?>
dir.inc.php
Code: Select all
<?
$host="#my_host#";
$username="#my_user#";
$password="#my_pass#";
$database="#my_database#";
$query="SELECT * FROM dir_links ORDER BY RAND() LIMIT 1";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result=mysql_query($query);
$num=mysql_numrows($result);
$url=mysql_result($result,$i,"url");
$title=mysql_result($result,$i,"title");
$description=mysql_result($result,$i,"description");
$i=0;
while ($i < $num)
{
echo "<b>Our Random Url for you:</b><a href=\"$url\">$title</a><br>Description:<br>$description";
$i++;
}
mysql_close();
?>
art.inc.php
Code: Select all
<?
$host="#my_host#";
$username="#my_user#";
$password="#my_pass#";
$database="#my_database#";
$query="SELECT * FROM ams_articles ORDER BY RAND() LIMIT 1";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result=mysql_query($query);
$num=mysql_numrows($result);
$title=mysql_result($result,$i,"article_title");
$url=mysql_result($result,$i,"article_urltitle");
$catid=mysql_result($result,$i,"article_categoryid");
$query2="SELECT * FROM ams_categories WHERE category_id='$catid' ORDER BY RAND() LIMIT 1";
$result2=mysql_query($query2);
$num2=mysql_numrows($result2);
$catname=mysql_result($result2,$i,"category_urltitle");
$i=0;
while ($i < $num)
{
echo "<b>Link:</b><a href=\"http://jimgeo.freehostia.com/article/$catname/$url.html\">$title</a>";
$i++;
}
mysql_close();
?>
bib.php
Code: Select all
<?
$host="#my_host#";
$username="#my_user#";
$password="#my_pass#";
$database="#my_database#";
$query="SELECT * FROM bible_verses ORDER BY RAND() LIMIT 1";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result=mysql_query($query);
$num=mysql_numrows($result);
$booknum=mysql_result($result,$i,"b");
$chapter=mysql_result($result,$i,"c");
$verse=mysql_result($result,$i,"v");
$query2="SELECT * FROM bible_books WHERE id='$booknum' ORDER BY RAND() LIMIT 1";
$result2=mysql_query($query2);
$num2=mysql_numrows($result2);
$book=mysql_result($result2,$i,"name");
$i=0;
while ($i < $num)
{
echo "<b>Link:</b><a href=\"http://www.ibelieve.uni.cc/bible/index.php?q=$book%2B$chapter.$verse\">$book $chapter : $verse</a>";
$i++;
}
mysql_close();
?>
Thanks for your interest
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Sun Aug 06, 2006 10:11 am
by jayshields
Move all the lines where you call mysql_result() inside the while() loops. Make sure they are before your echo call in the loop though.
Posted: Sun Aug 06, 2006 10:51 am
by jejimdude
THANX fixed