PHP & Javascript variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stephen.claw
Forum Newbie
Posts: 2
Joined: Thu Feb 26, 2004 5:40 pm

PHP & Javascript variables

Post by stephen.claw »

Hi,
can anyone help with my crap code. I basically have a mysql database full of articles. I wrote a query to access certain types of article. The results I put in to a table. In the while ($myrow = mysql_fetch_row($result)) I added a column in the table with a radio button.

printf("<TR><TD bgcolor=blue><input type=radio onclick=setCount(value) value=%s name=Lagp></TD>\n",$count);

I want to check which row is selected before going off and either printing or editing the article. The problem I have is that I want to make a php variable ie $rowCount = value (the form radio button value of the row which is selected) But I can't - please help me convert one type of variable to another.

Thanks
socrat
Forum Newbie
Posts: 1
Joined: Thu Feb 26, 2004 5:56 pm

answer.

Post by socrat »

wouldn't it be easyer to just add an id field to your table and have that stored in a variable? Heres an exaple

Code: Select all

the usual query $result= mysql_query("SELECT * FROM articles" );
$rows = mysql_num_rows($result);

for($i=0; $i<$rows; $i++) //will return true for each result.
&#123;
       $data = mysql_fetch_array($result)
       echo ($data&#1111;0]."<br />"); 
&#125;

// would be the article's id put that into your radio button value. than you can add a submit to that witch would submit each id selected to another query that would select the content and print it or whatever you wanna do with it.
       
&#125;
something along those lines, might not be exacly what you want but then again i dont have your script in front of me :)

Peace
Last edited by socrat on Sun Feb 29, 2004 12:07 am, edited 1 time in total.
stephen.claw
Forum Newbie
Posts: 2
Joined: Thu Feb 26, 2004 5:40 pm

Post by stephen.claw »

Hi,
I wanted to try and get around doing two queries. I put the results in to an array and then depending on the row selected I sumbit only that part of the array for printing. If I used the article number I wouldn't be able to map it to the array. The code looks like this:

$count = 1;
while ($myrow = mysql_fetch_row($result))
{
$found[$count] = $myrow;
printf("<TR><TD><input type=radio onclick=setCount(value) value=%s name=Lagp></TD>\n",$count);

printf("<TD>%s</TD><TD>%s</TD></TR>\n",$found[$count][0],$found
[$count][1]);

$count++;
}

In the setCount function that's where I try and set a php variable $rowCount to "value" as I then submit it like this:

<input type="hidden" name="Bilmake" value="<?php echo $found[$rowCount][0] ?>">
<input type="hidden" name="Tyretyp" value="<?php echo $found[$rowCount][1] ?>">

Does that make sense?

Cheers
Steve
Post Reply