Re: [PHP] WHERE problem

This is a discussion on Re: [PHP] WHERE problem within the PHP General forums, part of the PHP Programming Forums category; Different strokes for different folks... Might I toss a new recommendation into the mix? SELECT text FROM fortunes ORDER BY ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-20-2007
tg-php@gryffyndevelopment.com
 
Posts: n/a
Default Re: [PHP] WHERE problem

Different strokes for different folks...

Might I toss a new recommendation into the mix?

SELECT text FROM fortunes ORDER BY RAND() LIMIT 1;



= = = Original message = = =

N~~meth Zolt~~n wrote:
> 2007. 02. 20, kedd keltez~~ssel 08.17-kor Jim Lucas ezt ~~rta:
>> Mike Shanley wrote:
>>> I'd like to think I understood code a little better than this, but I've
>>> got a problem with my WHERE...
>>>
>>> I know it's the WHERE because I get a good result when I leave it out.
>>> And the random function is also working... I honestly can't figure it
>>> out. Thanks in advance for help with this laughable prob.
>>> ---------------------------
>>> // How many are there?
>>>
>>> $result = mysql_query("SELECT count(*) FROM fortunes");
>>> $max = mysql_result($result, 0);
>>>
>>> // Get randomized!... the moderated way...
>>>
>>> $randi = mt_rand(1, $max-1);
>>> $q = "SELECT text FROM fortunes WHERE index = '$randi'";
>>> $choose = mysql_query($q);
>>> $chosen1 = mysql_fetch_array($choose);

>> ARRAY???

>
> what's wrong with that?
> http://hu.php.net/manual/en/function...etch-array.php
>
> and then you can of course refer to it with indexes, both numeric and
> associative
> I don't see anything problematic with that...
>
> greets
> Zolt~~n N~~meth
>
>>> // Ready to ship...
>>>

>> Referring to it via an index... could be the problem
>>> $fortune = '<span class="quotecyc">&quot;' . $chosen1[0] .
>>> '&quot;<br/>-Omniversalism.com</span>';
>>>
>>> mysql_close();
>>>

>>
>> --
>> Enjoy,
>>
>> Jim Lucas
>>
>> Different eyes see different things. Different hearts beat on different
>> strings. But there are times for you and me when all such things agree.
>>
>> - Rush
>>

>

I would suggest using either assoc or row this way there is no
confusion. Plus it doesn't take as much resources. :)

--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different
strings. But there are times for you and me when all such things agree.

- Rush



__________________________________________________ _________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
Reply With Quote
  #2 (permalink)  
Old 02-20-2007
Németh Zoltán
 
Posts: n/a
Default Re: [PHP] WHERE problem

2007. 02. 20, kedd keltezéssel 11.39-kor tg-php@gryffyndevelopment.com
ezt Ã*rta:
> Different strokes for different folks...
>
> Might I toss a new recommendation into the mix?
>
> SELECT text FROM fortunes ORDER BY RAND() LIMIT 1;
>


that's not new :)
a couple of people recommended it earlier today/yesterday

this is perfect, but only if the table is not very large.
see
http://www.titov.net/2005/09/21/do-n...ws-from-table/

greets
Zoltán Németh

>
>
> = = = Original message = = =
>
> N~~meth Zolt~~n wrote:
> > 2007. 02. 20, kedd keltez~~ssel 08.17-kor Jim Lucas ezt ~~rta:
> >> Mike Shanley wrote:
> >>> I'd like to think I understood code a little better than this, but I've
> >>> got a problem with my WHERE...
> >>>
> >>> I know it's the WHERE because I get a good result when I leave it out.
> >>> And the random function is also working... I honestly can't figure it
> >>> out. Thanks in advance for help with this laughable prob.
> >>> ---------------------------
> >>> // How many are there?
> >>>
> >>> $result = mysql_query("SELECT count(*) FROM fortunes");
> >>> $max = mysql_result($result, 0);
> >>>
> >>> // Get randomized!... the moderated way...
> >>>
> >>> $randi = mt_rand(1, $max-1);
> >>> $q = "SELECT text FROM fortunes WHERE index = '$randi'";
> >>> $choose = mysql_query($q);
> >>> $chosen1 = mysql_fetch_array($choose);
> >> ARRAY???

> >
> > what's wrong with that?
> > http://hu.php.net/manual/en/function...etch-array.php
> >
> > and then you can of course refer to it with indexes, both numeric and
> > associative
> > I don't see anything problematic with that...
> >
> > greets
> > Zolt~~n N~~meth
> >
> >>> // Ready to ship...
> >>>
> >> Referring to it via an index... could be the problem
> >>> $fortune = '<span class="quotecyc">&quot;' . $chosen1[0] .
> >>> '&quot;<br/>-Omniversalism.com</span>';
> >>>
> >>> mysql_close();
> >>>
> >>
> >> --
> >> Enjoy,
> >>
> >> Jim Lucas
> >>
> >> Different eyes see different things. Different hearts beat on different
> >> strings. But there are times for you and me when all such things agree.
> >>
> >> - Rush
> >>

> >

> I would suggest using either assoc or row this way there is no
> confusion. Plus it doesn't take as much resources. :)
>
> --
> Enjoy,
>
> Jim Lucas
>
> Different eyes see different things. Different hearts beat on different
> strings. But there are times for you and me when all such things agree.
>
> - Rush
>
>
>
> __________________________________________________ _________
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.
>

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:22 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0