Jump to content


Photo

PHP mySQL database dynamic page layout

php mysql dynamicphp

Best Answer justin7410, 26 March 2013 - 03:16 PM

So i have answered my own question : 

 

the solution was simple.

;

 


 

    if(isset($_GET[$pageid])){
 

 

 

needs to be

 

 

 

    if(isset($pageid)){
 

 

hope this helps anyone else that has issues with this kind of problem , thanks for your help regardless jazzman


 

Go to the full post


  • Please log in to reply
5 replies to this topic

#1 justin7410

justin7410

    Advanced Member

  • Members
  • PipPipPip
  • 106 posts

Posted 25 March 2013 - 09:57 PM

Hey guys ,

 

I am currently trying to create a dynamic page layout using data that i am pulling from my database.(mysql)

 

i have created the a href to show page.php?title=$title&id=$Id 

 

then i created the page.php where the code will be inserted to spit out the page after matching the ids

 

this is where the problem ensues, i have created some conditionals 

 
At first, i had this code:

 

    <?
    $content  = mysql_query("SELECT * 
    FROM  `content` 
    ORDER BY rating, votes DESC 
    LIMIT 0 , 30");
    ?>


    <?
    if(isset($_GET['id'])){
    $row = mysql_fetch_assoc($content);
    if (isset($row['id'])){ 
    extract($row);
    }
    }
    if (!isset($_GET['movieid'])){
    header("Location: i.php");
    exit();
    }


    print_r ($rows); //shows the entire array
    ?>
 

 

 

but my problem that i was encountering was that any link i clicked was not producing a different ID to the URL, it was just spitting out the same array for every link i clicked on . 

 

i then tried hunting my $_GET and figured to find where the variables are coming from. and to change my SQL query to locate the correct variable

 

 

 


i figured that the issue must be that my sql statement is not matching the $_GET to the field of the Database( 'id' ) , although that is the name of the field.
 
i then changed it up to this simple code:
    $pageid = $_GET['id'];
    $title = $_GET['title'];
    $idQuery = mysql_query(" SELECT * FROM  `content` WHERE 'id'=$pageid LIMIT 0 , 20");


    if(isset($_GET[$id])){
    $rows = mysql_fetch_assoc($idQuery);
    if (isset($rows['id'])){ 
    extract($rows);
    }
    } 
    print_r ($rows) // nothing is found 
 

 

 

i really wish to figure this out without being spoon fed the answer, but i have been stuck on this for a few nights and really could use some suggestions.

 

thanks guys


Edited by justin7410, 25 March 2013 - 09:58 PM.


#2 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,631 posts
  • LocationMississauga, Canada

Posted 25 March 2013 - 10:03 PM

Try,

    $idQuery = mysql_query(" SELECT * FROM  `content` WHERE 'id'=$pageid LIMIT 0 , 20");

to

    $idQuery = mysql_query(" SELECT * FROM  `content` WHERE `id`=$pageid LIMIT 0 , 20");



#3 justin7410

justin7410

    Advanced Member

  • Members
  • PipPipPip
  • 106 posts

Posted 25 March 2013 - 11:21 PM

Hey Jazzman, 

 

thanks for the reply. 

 

i really thought that back tick would help solve the issue, that was a typo on my part and was not a problem in the code.

 

i am still trying to solve this issue. 

 

my print_r does not return my $rows nor can i echo any variables from my extract(). 

 

any other suggestions guys ??



#4 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,631 posts
  • LocationMississauga, Canada

Posted 26 March 2013 - 06:32 AM

Where do you declare this $id:

 

 if(isset($_GET[$id])){
...........


#5 justin7410

justin7410

    Advanced Member

  • Members
  • PipPipPip
  • 106 posts

Posted 26 March 2013 - 02:17 PM

Where do you declare this $id:

 

 if(isset($_GET[$id])){
...........

above the query ... check the bottom of the first post.

 

the variable is named $pageid .. not $id thats a typo on the question.

 

it would be  if(isset($_GET[$pageid])){



#6 justin7410

justin7410

    Advanced Member

  • Members
  • PipPipPip
  • 106 posts

Posted 26 March 2013 - 03:16 PM   Best Answer

So i have answered my own question : 

 

the solution was simple.

;

 


 

    if(isset($_GET[$pageid])){
 

 

 

needs to be

 

 

 

    if(isset($pageid)){
 

 

hope this helps anyone else that has issues with this kind of problem , thanks for your help regardless jazzman


 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com