List Info

Thread: PHP Help using a Drop to Select Mysql records




PHP Help using a Drop to Select Mysql records
user name
2006-10-13 01:03:54
I am creating a list of games for my website and need
to know how to allow users to select each game by the
title by using a drop down


i have setup a script that changes game when the record
'id' changes like below this would play 'game 25' when
added! to the rest of the script

---------------------------------

// SQL statement
$sql = "SELECT * FROM test where id=25";

---------------------------------


my problem is allowing users to use a drop down to make
the records change like from 25,21,15 to open other
games/records


how do I make a drop down that can select different records
at this part of the script, if you know that also is there
a way i can link them to the correct titles


eg: I want to use dropdown to select

game1 = script to change to---> $sql = "SELECT *
FROM test where id=1";
game2 = script to change to---> $sql = "SELECT *
FROM test where id=2";

how can i make this work on a drop down with game titles??


Thanks in advance it would be appreciated if someone can
help
regards Dan from bond,UK


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "PHP & MySQL" group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to
phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://g
roups-beta.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

PHP Help using a Drop to Select Mysql records
user name
2006-10-13 12:40:27
First you get the list of games
 
$strQuery="SELECT * FROM TEST";
$recordSet=mysql_query($strQuery,$connection);
 
build the select option
 
$strSelect='<SELECT NAME=X>';
 
while ($row= mysql_fetch_array($recordSet))
{
  $strSelect.='<OPTION VALUE='.$row['gameId'].'>'.$row['gameName'].'</OPTION>';
}
$strSelect.='</SELECT>';
 
print this select between the form tag.
after selection process is completed, you should&nbsp;post to same page.
&nbsp;
now you get 
gameId=$_POST['X']&nbsp;
&nbsp;
by using this gameid you can exicute your query as follows
 
$sql = "SELECT * FROM test where id=".gameId;
&nbsp;
 ;

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "PHP & MySQL"; group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://groups-beta.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

PHP Help using a Drop to Select Mysql records
user name
2006-10-13 14:26:48
Thanks for the help

I have just created the php page and amended the fields from

gameid -> id     gamename -> name


I was a little confused in doing this but i just wanted you
to check if
ive done this correct

file name new.php

<?php

$conn = mysql_connect("localhost",
"root", "") or die(mysql_error());
mysql_select_db("test",$conn)  or
die(mysql_error());


<html><body>
<form action="<?php echo
$_SERVER['PHP_SELF'];?>" method="POST"
>


$strQuery="SELECT * FROM TEST";
$recordSet=mysql_query($strQuery,$connection);


$strSelect='<SELECT NAME=X>';


while ($row= mysql_fetch_array($recordSet))
{
  $strSelect.='<OPTION
VALUE='.$row['Id'].'>'.$row['name'].'</OPTION>';


}


$strSelect.='</SELECT>';

?>
</form></body>





<?
Id=$_POST['X']

$sql = "SELECT * FROM test where id=".Id;


rest of script.......


?>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "PHP & MySQL" group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to
phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://g
roups-beta.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )