对于所有这些都很新颖,所以如果我以疯狂的方式讨论我的困惑,请告诉我!php mySQL,通过数字检索一行,将值存储为assoc.array
我在MySQL数据库中的列标题,超链接,ImageLink的
我想PHP来随机选择一个排一个表,然后就可以标题,超链接和ImageLink的另存为PHP变量。 (这样我就可以然后将它们输出到HTML)
,所以我可以有如
psuedoey代码的想法
chosenNumber = randomNumber();
$chosenTitle = title[chosenNumber]
$chosenHyperlink = hyperlink[chosenNumber]
$chosenImagelink = imagelink[chosenNumber]
echo "<a href = $chosenTitle><img src= $chosenImagelink/> $chosenTitle </a>";
我想我需要在这里使用assoc命令阵列喜欢这一点,但我很困惑,因为我看遍了各种PHP的MySQL FETCH_ASSOC fetch_row等,并不能找到做哪一个我需要:(
我至今是
// database table name information
$number = "number";
$title = "title";
$hyperlink = "hyperlink";
$imagelink = "imagelink";
// sql to select all rows of adverts
$sql = "SELECT $number, $title, $hyperlink, $imagelink FROM $table";
//execute the sql
$data = mysql_query($sql, $link);
//count the number of rows in the table
$bannerCount = mysql_num_rows($data);
//generate a random number between 0 and the number of rows
$randomNumber = mt_rand(0, $bannerCount); //do I need to do bannerCount-1 or similar here?
$chosenNumber = $randomNumber;
//select data from a random row
第一时间发帖,请善待,并感谢您的任何答复或解释!
请注意 - 您可以通过点击投票分数下方的复选标记将答案标记为“接受的答案”。欢迎来到堆栈溢出! – gnarf 2010-05-24 23:30:50