Jump to content

Archived

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

Crashdowngurl

Information not pulling from database

Recommended Posts

I've been working on this for hours and I can't find whats going wrong to save my life. I have a feeling this is one of those situations where I am going to feel dumb for not realizing the problem :) I know this is probably something to do with $_GET['id'] but I am unsure how to structure it.

I am creating a page that will pull entries from a database and display a list of the enteries on the side of the page, when you click on one, it will display that entry's data. I am working doing this for my portfolio pieces for school, so each of my projects has a name that is supposed to call the id, title, type, image, description, and link from the database.

The list of entries displays perfectly on the side, however, when I click on the them, no information all appears. I've attached the code below. Please help me!



[code]<?php
error_reporting(0);

include $_Server['DOCUMENT_ROOT'].'includes/header.html';

require('includes/database.php');                




// What are we looking for? (Decide Query)
$query        =    "UPDATE fbnet_portfolio WHERE id=1 SET count = count + 1";
    // Store info in debug
    $debuginfo    .=    "COUNTER QUERY ".$query;   $debugtotal=$debugtotal+1;

// Update the counter table setting the total hits up by one
mysql_query($query,$db);                        





if (!isset($type) or $type=="")
{
    $type="website";
}
// Format if $id is not set or if it ="" then set it to "1"
if (!isset($id) or $id=="")
{
    $id="1";  
}



$result = mysql_query("SELECT id, title, type FROM portfolio WHERE type='website'");
while($result && list($id, $title, $type)=mysql_fetch_row($result))
{
    $portfoliolist    .=    "<a href=\"webdesign.php?id=" . $id . "\">" . $title . "</a><br />";
}

// What are we looking for? (Decide Query)
$query        =    "SELECT * FROM portfolio WHERE id=".$id;
    // Store info in debug
    $debuginfo    .=    "INFO QUERY ".$query;   $debugtotal=$debugtotal+1;
$result = mysql_query($query);

//while ($myrow = mysql_fetch_row($result))
if ($myrow = @mysql_fetch_array($result))
{

    $title        =    $myrow[1];
    $type        =    $myrow[2];
    $image        =    $myrow[3];
    $description            =    $myrow[4];
    $link    =    $myrow[5];
      
}



?> [/code]


I'm using the following to pull the information from the database:


[code]<?PHP echo($title); ?> [/code]

Like I said, the list is working fine, it's just when you click on the links, the information relative to the id number is not displaying.

Any help with this would be EXTREMELY appreciated :)

Thank you!
-Emma

Share this post


Link to post
Share on other sites
[code]
$query        =    "SELECT * FROM portfolio WHERE id=".$id;
[/code]

i think should be

[code]
$query        =    "SELECT * FROM portfolio WHERE id='$id'";
[/code]

Try that out see how it works.

Share this post


Link to post
Share on other sites
I would suggest removing the error suppression ("@" symbol) to see if there are any errors with the query.

Share this post


Link to post
Share on other sites
[!--quoteo(post=370686:date=May 2 2006, 03:07 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 2 2006, 03:07 PM) [snapback]370686[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I would suggest removing the error suppression ("@" symbol) to see if there are any errors with the query.
[/quote]

I removed it and the page displays no errors. Any other thoughts?

Share this post


Link to post
Share on other sites
[!--quoteo(post=370694:date=May 2 2006, 01:32 PM:name=Crashdowngurl)--][div class=\'quotetop\']QUOTE(Crashdowngurl @ May 2 2006, 01:32 PM) [snapback]370694[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I removed it and the page displays no errors. Any other thoughts?
[/quote]

under
[code]$result = mysql_query($query);[/code]

Try
[code]if(!$result){ echo mysql_error(); }[/code]

That should give u a message. Hopefully!

Share this post


Link to post
Share on other sites
No message :( PHP hates me!

[code]
$query        =    "SELECT * FROM portfolio WHERE id='$id'";
    // Store info in debug
    $debuginfo    .=    "INFO QUERY ".$query;   $debugtotal=$debugtotal+1;
$result = mysql_query($query);
if(!$result){ echo mysql_error(); }[/code]

Thats how I added it in there, page still displays fine, but doesn't show any of the information.

Share this post


Link to post
Share on other sites
Plz change it to
[b]
// What are we looking for? (Decide Query)
$query = "SELECT * FROM portfolio WHERE id='$id'";
$result = mysql_query($query,$db);

while ($myrow = mysql_fetch_row($result))
{

$title = $myrow[1];
$type = $myrow[2];
$image = $myrow[3];
$description = $myrow[4];
$link = $myrow[5];

}
[/b]

Share this post


Link to post
Share on other sites

Hi,

First u have to check the $id value is a valued one or not.

print the value of $id. ( echo $id).

then .,

1. print the query.
2. copy the query and paste it into the PHYMYADMIN >> SQL section
( Because of first u have test the query passed is correct or not)
3.still u have problem.
4. make the query as

SELECT * FROM portfolio WHERE id='.$_GET['id'].'";


try this please.

Umasankar Subramanian

Share this post


Link to post
Share on other sites
First, as Subramanian said, $id is not even set yet. If you ar passing it thru the url, first thing at the top should be

[code]$id = $_GET['id'];[/code]

or use Subramanian's query.

Without that you will never get anything including errors because your query is looking for a null or 0 id. This is perfectly fine for a query which is why you get no errors, and you get no results because the 0 or null id doesn't exist.

Share this post


Link to post
Share on other sites

×

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.