nita Posted May 2, 2007 Share Posted May 2, 2007 HI. I.m rather new to php and mysql. I would like to get some help with this basic script below. Script is printing names of the movies as a links with specified id. Once is clicked on - it meant to refresh index.php and display full info about choosen movie. But is not, instead is printing entire list of movies again. you can this script in action at: www.nita-on-line.com/dynurl/ <? include "connectdb.php"; if (isset($id)) // looking at a record with speified id { $S1="SELECT * from movies where id='$id'"; $S2=mysql_query($S1); $S3=mysql_fetch_array($S2); print "$S3[name]"; print "$S3[plot]"; } else if(!isset($id)) // looking at the root { $D1="SELECT * from movies"; $D2=mysql_query($D1); while($D3=mysql_fetch_array($D2)) { print "<A href='index.php?ID=$D3[id]'>$D3[name]</a><br>"; } } ?> I'm not sure what is wrong, i will be very happy if someone can help with this code. Im aware how basic it is, but im stuck and would like to move on. Thank you for your solution in advance. Nita nita.travel@ekit.com Quote Link to comment https://forums.phpfreaks.com/topic/49640-solved-dynamic-url-with-php-mysql/ Share on other sites More sharing options...
taith Posted May 2, 2007 Share Posted May 2, 2007 <? include "connectdb.php"; if(is_numeric($_GET[id])){ $S2=mysql_query("SELECT * from movies where id='$_GET[id]' LIMIT 1"); $S3=mysql_fetch_array($S2); print "$S3[name]"; print "$S3[plot]"; }else{ $D2=mysql_query("SELECT * from movies"); while($D3=mysql_fetch_array($D2)){ print "<A href='index.php?ID=$D3[id]'>$D3[name]</a><br>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49640-solved-dynamic-url-with-php-mysql/#findComment-243363 Share on other sites More sharing options...
nita Posted May 2, 2007 Author Share Posted May 2, 2007 Thx for your replay. but the problem is still not solved, exactly the same think is happening. Browser will not show details of specified movie / id. Print the entire list again, instead. I dont know if it matters much what is in connectdb.php file. Listing below: <? //connect to database $conn = mysql_connect("localhost", "login", "password") or die(mysql_error()); mysql_select_db("nita",$conn) or die(mysql_error()); ?> Well, maybe there is a problem with GET ?? Thanks a lot for further help !!! Nita Quote Link to comment https://forums.phpfreaks.com/topic/49640-solved-dynamic-url-with-php-mysql/#findComment-243393 Share on other sites More sharing options...
nita Posted May 2, 2007 Author Share Posted May 2, 2007 I did modarate my code a bit (after looking up in some other sources) <? include "connectdb.php"; if(isset($_GET['id'])) { $id=$_GET['id']; $S2=mysql_query("SELECT * from movies where id='$id' LIMIT 1"); $S3=mysql_fetch_array($S2); print "$S3[name]"; print "$S3[plot]"; } else { $D2=mysql_query("SELECT * from movies"); while($D3=mysql_fetch_array($D2)) { print "<A href='index.php?id=$D3[id]'>$D3[name]</a><br>"; } } ?> There is no problem of geting the names of the movies as a links with specified id. Problem is with display a single record (within same index.php file). Look at: www.nita-on-line.com/dynurl/ Browser do listing from the database with or without specified id. (!!worng if - else statment ??) It's really confusing me. i tried many options, but non of them seems to work. I know i cant be to difficult couse this is very beginning of php/mysql run websites. if someone can give me some tip, please. Quote Link to comment https://forums.phpfreaks.com/topic/49640-solved-dynamic-url-with-php-mysql/#findComment-243446 Share on other sites More sharing options...
taith Posted May 2, 2007 Share Posted May 2, 2007 theres your problem... $vars are CaSe SpEcIfIc... you are $_GET['id']'ing in lowercase, and you link's ?ID='s are uppercase... Quote Link to comment https://forums.phpfreaks.com/topic/49640-solved-dynamic-url-with-php-mysql/#findComment-243449 Share on other sites More sharing options...
nita Posted May 2, 2007 Author Share Posted May 2, 2007 thanks a lot Teith, it's working perfectly now. Good Day !! Quote Link to comment https://forums.phpfreaks.com/topic/49640-solved-dynamic-url-with-php-mysql/#findComment-243454 Share on other sites More sharing options...
nita Posted May 2, 2007 Author Share Posted May 2, 2007 Problem has been solved !!! Thx to Teith Corect code: <? include "connectdb.php"; if(isset($_GET['id'])) { $id=$_GET['id']; $S2=mysql_query("SELECT * from movies where id='$id' LIMIT 1"); $S3=mysql_fetch_array($S2); print "$S3[name]"; print "$S3[plot]"; } else { $D2=mysql_query("SELECT * from movies"); while($D3=mysql_fetch_array($D2)) { print "<A href='index.php?id=$D3[id]'>$D3[name]</a><br>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49640-solved-dynamic-url-with-php-mysql/#findComment-243456 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.