Re: Problems with rand and arrays

From: Date: Thu, 07 Dec 2000 21:51:13 +0000
Subject: Re: Problems with rand and arrays
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-29218@lists.php.net to get a copy of this message
Well I don't know if I have done any progress but this is the code I have now: $b = 0; $arrRandIdx = array_rand($arrRes, 3); $rand_text_result = query("SELECT * FROM poems WHERE id=" . $arrRes[$arrRandIdx[0]] . " or id=" . $arrRes[$arrRandIdx[1]] . " or id=" . $arrRes[$arrRandIdx[2]]); while ($row = mysql_fetch_array($rand_text_result)) { $random[$b] = $row["text"]; $b++; } $random1 = "<a href='something.php?id='" . $arrRes[$arrRandIdx[0]] .. "'>" . $random[0] . "</a>"; $random2 = "<a href='something.php?id='" . $arrRes[$arrRandIdx[1]] .. "'>" . $random[1] . "</a>"; $random3 = "<a href='something.php?id='" . $arrRes[$arrRandIdx[2]] .. "'>" . $random[2] . "</a>"; The problem is that I don't get any 'id's in the link it says: 'something.php?id=' and that's no good =) I can't figure out what I am doing wrong here, so plz! help me... ----- Original Message ----- From: "Pavel Jartsev" <papi@digitalfruit.ee> To: "Broder B" <broder_b@chello.se>; <php-general@lists.php.net> Sent: Thursday, December 07, 2000 6:41 PM Subject: Re: [PHP] Problems with rand and arrays > Broder B wrote: > > > > Yeah I think it would work if it were't for this error: > > > > Parse error: parse error, expecting `']'' in C:\Program\Apache > > Group\Apache\htdocs/boa/home.php on line 24 > > > > I just can't figure this one out. > > > > $arrRandIdx = array_rand($arrRes, 3); > > > > $rand_text_result = query("SELECT * FROM poems WHERE > > id=$arrRes[$arrRandIdx[0]]") > > > > ok, then this way: > $rand_text_result = query( "SELECT * FROM poems WHERE > id=".$arrRes[$arrRandIdx[0]] ); > > > -- > Pavel a.k.a. Papi >

« previous php.general (#29218) next »