PHP help! (in Off-topic)


[Beo]AggroHippie March 19 2006 7:00 PM EST

ok, I am having this problem with php, its probably my stupid just showing, but any help would be really appreciated... mt_srand((double)microtime() * 1000000); $bg_num = mt_rand(1,10); $background_select_string = "SELECT * FROM background WHERE bg_num = '$bg_num'"; $background_select = mysql_query($background_select_string) or die(mysql_error()); $value = mysql_fetch_row($background_select); echo "(container tag)BODY bgcolor=" .$value[background_color]. "(container tag)"; ok, basically, what I want to do is make a random background appear after every click, merely for the sake of baing able to. now, I think the error is in the msql fetch row, I dont know exactly why this is set up the way it is, the teacher wishes it that way, so if I could just get an explanation as to what this statement is doing, and what could be done differently I would thank them alot, in public. (is that payment enough?) what I was thinking was, use the same mysql fetching that worked for my subject tabs on the top row (the website is aikidoterms.com if your interested, I havent added content in yet, or color co-ordination schemes...

AdminQBVerifex [Serenity In Chaos] March 19 2006 7:11 PM EST

Beowulf there are plenty of us out here to help, but you will really need to use better formatting then that for us to help you, please, it gives me a headache trying to read that giant paragraph, code included.

[Beo]AggroHippie March 19 2006 7:32 PM EST

mt_srand((double)microtime() * 1000000);
$bg_num = mt_rand(1,10);
$background_select_string = "SELECT * FROM background WHERE bg_num = '$bg_num'";
$background_select = mysql_query($background_select_string) or die(mysql_error());
$value = mysql_fetch_row($background_select);
echo "(container tag)BODY bgcolor=" .$value[background_color]. "(container tag)";

[Beo]AggroHippie March 19 2006 7:33 PM EST

sorry, got caught up in changing it so I wouldnt have the spell checker annihilate me...

[Beo]AggroHippie March 19 2006 8:53 PM EST

heh, crisis over... found out I cannot identify it be the field, but as a number because of the array type...

bartjan March 20 2006 12:54 AM EST

$value[background_color] should be $value['background_color']

Do not access $value by numbers when also doing a select *, as that causes lots of problems if someone decides to change the database layout, for example by adding or removing a row before the row you're interested in.

Never ever use * in a select, unless there's a real need for it...

AdminQBVerifex [Serenity In Chaos] March 20 2006 1:31 AM EST

I agree.
This thread is closed to new posts. However, you are welcome to reference it from a new thread; link this with the html <a href="/bboard/q-and-a-fetch-msg.tcl?msg_id=001kQ6">PHP help!</a>