doddsey_65 Posted April 2, 2010 Share Posted April 2, 2010 I am creating a page that lists all results found in the database that match the given username. It sets the url to that of the id. eg tutorials.php?id=1 Up to now i have been using If statements like so: if url = tutorials.php?id=1 then show video 1 but since i have around 150 videos this option isnt feasable, as i would also like people to be able to submit their own. This was I will have to do all of it. I was told there was a simple loop thing i could do with the for each./ how would i go about this? Quote Link to comment https://forums.phpfreaks.com/topic/197374-for-each/ Share on other sites More sharing options...
RaythMistwalker Posted April 2, 2010 Share Posted April 2, 2010 when u load the page as you have described do: $id = $_GET['id'] Then you can save what video has that idea in a mysql database so you query the database to display that video when that id is selected. Quote Link to comment https://forums.phpfreaks.com/topic/197374-for-each/#findComment-1035955 Share on other sites More sharing options...
doddsey_65 Posted April 2, 2010 Author Share Posted April 2, 2010 i dont understand. lets say i have the variables: $id which is the id as it appears in the db $name which is the name of the record in the db $link which is a youtube embedd code which is in the database how would i get it to display the details of the specific one they click on. Quote Link to comment https://forums.phpfreaks.com/topic/197374-for-each/#findComment-1035957 Share on other sites More sharing options...
RaythMistwalker Posted April 2, 2010 Share Posted April 2, 2010 <?php $id = $_GET['id'] $link = mysql_connect(HOST, USER, PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DATABASE); if(!$db) { die("Unable to select database"); } $query = "SELECT `youtube` FROM `videos` WHERE `id`=$id"; $result = mysql_query($query); if (!$result) { die("Video Does not exist!"); } $youtube = mysql_result($result,youtube); ?> <embed src='<?php echo $youtube; ?>' width='x' height='y'> Try that editing the values needed. Quote Link to comment https://forums.phpfreaks.com/topic/197374-for-each/#findComment-1035958 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.