Jump to content

PHP newbie.... completely confused!!


Ben2

Recommended Posts

Hi there,

 

I am hoping someone here can help me with my problem...

 

I have created some php code that I thought would do what I require but it just will not work!

 

What I require is to connect to my database and get information from one table to see if a video has been marked as featured, if so then get some more information from that table and then get the users "NickName" from another table to show with the video screenshot.

 

I have tried playing around with the code to see if I can get it to work but I have not been able to.

 

Here is my code so far:

 

mysql_connect("localhost", "*****", "*****") or die(mysql_error());
mysql_select_db("*****") or die(mysql_error());

    


$dir = "*****/*****/*****/";

    



$sql = "SELECT RayVideoFiles.ID, RayVideoFiles.Owner, RayVideoFiles.Views, RayVideoFiles.Featured, RayVideoFiles.Uri, RayVideoFiles.Title, Profiles.ID, Profiles.NickName\n"
    . "FROM RayVideoFiles\n"
    . "INNER JOIN Profiles\n"
    . "ON RayVideoFiles.Owner=Profiles.ID\n"
    . "ORDER BY Profiles.ID LIMIT 0, 30 ";


while($row = mysql_fetch_array($sql)) {

    

    

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    

    

    

<html xmlns="http://www.w3.org/1999/xhtml">

    

    

    

<head>

    


    

    

    

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">';

    

    

    

    


    

    

echo '.centering {display: block; margin-left: auto; margin-right: auto; margin-top:10px; }';

    

    

echo '</style></head><body>';

    

    

echo '<div style="margin-left:auto; margin-right:auto; width:170px; background-color:#fff; padding:10px;"><div class="boxContent"><div class="dbContent">
<a href="m/videos/view/'.$row[uri].'"><img src="'.$dir.''.$row[iD].'.jpg" width="140px" height="110px" style="border:6px double #545565;"/></div></a><br /><p><div class="sys_file_search_title" style="margin-top:-15px;"><a href="m/videos/view/'.$row[uri].'">'.$row[Title].'</a><br /></div><div class="sys_file_search_from" style="margin-top:0px;">From <a href="'.$row[NickName].'">'.$row[NickName].'</a><br /></div><div class="sys_file_search_when" style="margin-top:0px;">'.$row[Views].' Views</p></div></div></div>';
}

 

I thank you in advance for any help that you can give me on this matter.

Link to comment
Share on other sites

You need to use quotes on the key names for $row.

 

Like $row[uri] should be $row['Uri'].

 

Thank you for your quick reply,

 

I have changed my code so that it now looks like this:

 

mysql_connect("localhost", "*****", "******") or die(mysql_error());
mysql_select_db("******") or die(mysql_error());
    
$dir = "********";    

$sql = "SELECT RayVideoFiles.ID, RayVideoFiles.Owner, RayVideoFiles.Views, RayVideoFiles.Featured, RayVideoFiles.Uri, RayVideoFiles.Title, Profiles.ID, Profiles.NickName\n"
    . "FROM RayVideoFiles\n"
    . "INNER JOIN Profiles\n"
    . "ON RayVideoFiles.Owner=Profiles.ID\n"
    . "ORDER BY Profiles.ID LIMIT 0, 30 ";


while($row = mysql_fetch_array($sql)) {
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>    
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">';
                
        echo '.centering {display: block; margin-left: auto; margin-right: auto; margin-top:10px; }';

        echo '</style></head><body>';

        echo '<div style="margin-left:auto; margin-right:auto; width:170px; background-color:#fff; padding:10px;"><div class="boxContent"><div class="dbContent">
<a href="m/videos/view/'.$row['Uri'].'"><img src="'.$dir.''.$row['ID'].'.jpg" width="140px" height="110px" style="border:6px double #545565;"/></div></a><br /><p><div class="sys_file_search_title" style="margin-top:-15px;"><a href="m/videos/view/'.$row['Uri'].'">'.$row['Title'].'</a><br /></div><div class="sys_file_search_from" style="margin-top:0px;">From <a href="'.$row['NickName'].'">'.$row['NickName'].'</a><br /></div><div class="sys_file_search_when" style="margin-top:0px;">'.$row['Views'].' Views</p></div></div></div>';
}

 

But unfortunatly it still does not work correctly, When I load the page nothing is produced.

Link to comment
Share on other sites

You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that problems like Pikachu2000 pointed out would be, well, pointed out to you. There would have been an error at the mysql_fetch_array() statement due to the fact that you are not passing it a result resource from a mysql_query() statement.

Link to comment
Share on other sites

You never execute the query with mysql_query().

 

Thank you very much for your advice it worked great!!

 

You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that problems like Pikachu2000 pointed out would be, well, pointed out to you. There would have been an error at the mysql_fetch_array() statement due to the fact that you are not passing it a result resource from a mysql_query() statement.

 

Unfortunatly I am new to php, MySQL and phpMyAdmin so I do not really know what tools I should be using. I have just been using "notepad" and Dreamweaver to create my code.

 

Can you recommend any tools/software that would be better to use for a beginner like me?

Link to comment
Share on other sites

error_reporting and display_errors are two php.ini settings.

 

Oh well that does not make a lot of sense to me as I am such a "newbie" lol but I will look into what they are so that I will not miss something like this again as they will inform me of simple errors like this.

 

Thanks again for your help

Link to comment
Share on other sites

Can you recommend any tools/software that would be better to use for a beginner like me?

 

Yes I can, if you like a nice editor use Netbeans the php version. It's 12 million times better than dreamweaver. And it's free and while coding it gives tips and hints.

Also for testing I would do that local, I use xampp, almost plug and play server. It's not the best but it's easy to install even my turtles can do it if i would train them to use my keyboard. and also xampp is free.

 

If you installed xampp, PHP is also on your computer and you can easily see stuff like php.ini

Link to comment
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.