Jump to content

For each


doddsey_65

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/197374-for-each/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/197374-for-each/#findComment-1035957
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/197374-for-each/#findComment-1035958
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.