Jump to content

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