Jump to content

navmenu links storing in get


Cflax

Recommended Posts

Here is my current navmenu.php i pulls category names from a table and makes them links so if you add a category later, it's automatically added to the menu.

That part works.

The problem I am running into now, is that i want the the links to store $row1 data via GET (I know its a lot to store there, but it's how im doing it this time around)

I thought the following code would successfully store the data i wanted, but when i looked at my viewlistings.php no information is showing up.

 

navmenu.php

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

$query = "SELECT * FROM ob_category";
$data = mysqli_query($dbc, $query);

$query1 = "SELECT * FROM ob_listings";
$data1 = mysqli_query($dbc, $query1);
$row1 = mysqli_fetch_array($data1);

$links = array();
while($row=mysqli_fetch_array($data)){
     $links[] =  '<a href="viewlistings.php?listing_id=' . $row1['listing_id'] . '&subject=' . $row1['subject'] .
      '&description=' . $row1['description'] . '&price=' . $row1['price'] .  '&user_id=' . $row1['user_id'] . '&category_id=' . $row1['category_id'] . '&date=' . $row1['date'] . '&city=' . $row1['city'] . '&state=' . $row1['state'] .'">' . $row['name'] . '</a>';

}
echo implode(' &#8226; ', $links);


echo '<hr />';

 

viewlistings.php

if (isset($_GET['listing_id']) && isset($_GET['subject']) && isset($_GET['description']) && isset($_GET['price']) && isset($_GET['user_id']) && isset($_GET['category_id']) && isset($_GET['date']) && isset($_GET['city']) && isset($_GET['state'])) {
    // Grab the score data from the GET
    $listing_id = $_GET['listing_id'];
    $subject = $_GET['subject'];
    $description = $_GET['description'];
$price = $_GET['price'];
    $user_id = $_GET['user_id'];
    $category_id = $_GET['category_id'];
$date = $_GET['date'];
    $city = $_GET['city'];
    $state = $_GET['state'];
   
    // Connect to the database 
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 

  // Retrieve the user data from MySQL
  $query = 'SELECT * FROM ob_listings WHERE category_id="' . $category_id . '" ORDER BY date DESC';
  $data = mysqli_query($dbc, $query);
   }
  // Loop through the array of user data, formatting it as HTML
  echo '<h4>' . $cateory_id . ':</h4>';
  echo '<table><tr><td><strong>Listing</strong></td><td><strong>Location</strong></td><td><strong>Date Posted</strong></td><td><strong>Price</strong></td></tr>';
  while ($row = mysqli_fetch_array($data)) { 
echo '<tr><td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['subject'] . '</a></td>';
echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['city'] . ', ' . $row['state'] . '</a></td>';
echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['date'] . '</a></td>';
echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['price'] . '</a></td></tr>';
  }
  
  echo '</table>';

 

I would REALLY REALLY appreciate it if someone could help me get this working... its the last part of my site i need to get working before i turn it in thursday.

thanks in advance :)

Im almost positive that the problem is in navmenu.php because when I click on the links all the fields are empty in the URL.

Link to comment
Share on other sites

*EDIT*

i have come to find that the code is kind of working. It's doing what i want it to do, but when viewlistings.php stores the get values its only storing the first get value, resulting in only displaying ONE listing

any ideas???

Link to comment
Share on other sites

okay I see what you are doing..your creating a dynamic link based on all of these variables in the database..at first glance i do not see what is wrong with your code...do you receive any errors when running this script?

Link to comment
Share on other sites

no, it just displays the first entry it gets on all links...im still unsure of why it

i thought "maybe storing the get results as variables in viewlistings.php might lock in JUST the first result" so i tried pulling the info from get everytime i needed it, instead of assigning it a value...

still the same problem...

here is what i changed viewlistings.php to with still no luck...this way they continue to just show the first result

if (isset($_GET['listing_id']) && isset($_GET['subject']) && isset($_GET['description']) && isset($_GET['price']) && isset($_GET['user_id']) && isset($_GET['category_id']) && isset($_GET['date']) && isset($_GET['city']) && isset($_GET['state'])) {
   /* // Grab the score data from the GET
    $listing_id = $_GET['listing_id'];
    $subject = $_GET['subject'];
    $description = $_GET['description'];
$price = $_GET['price'];
    $user_id = $_GET['user_id'];
    $category_id = $_GET['category_id'];
$date = $_GET['date'];
    $city = $_GET['city'];
    $state = $_GET['state'];*/
   
    // Connect to the database 
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 

  // Retrieve the user data from MySQL
  $query = 'SELECT * FROM ob_listings WHERE category_id="' . $_GET['category_id'] . '" ORDER BY date DESC';
  $data = mysqli_query($dbc, $query);
   }
  // Loop through the array of user data, formatting it as HTML
  echo '<h4>' . $_GET['category_id'] . ':</h4>';
  echo '<table><tr><td><strong>Listing</strong></td><td><strong>Location</strong></td><td><strong>Date Posted</strong></td><td><strong>Price</strong></td></tr>';
  while ($row = mysqli_fetch_array($data)) { 
echo '<tr><td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['subject'] . '</a></td>';
echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['city'] . ', ' . $row['state'] . '</a></td>';
echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['date'] . '</a></td>';
echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['price'] . '</a></td></tr>';
  }
  
  echo '</table>';

Link to comment
Share on other sites

at this point im open for suggestions for a different way to make my links display only results with a value equal to their name using my navmenu.php file and my viewlistings.php file

Keep in mind that I do need to keep the information the link shows dynamic so that if a category is added to the table, a link is created automatically

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.