Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.