PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 22, 2022

[FIXED] How to make Indivdual array results, into links?

 July 22, 2022     php, php-5.4     No comments   

Issue

I am trying to return an array of results from php, and each result is a link. When a link is clicked, it will go into another php that echo the details that are related to link/array clicked. But i am not very sure how to do that. What i attached below is the array echoed out. Please any thoughts would be good. Thanks for your time.

<?php
ini_set('display_errors', 1); error_reporting(E_ALL);


include 'connect.php';
$username=$_SESSION['username'];


$result=mysqli_query($con,"SELECT * FROM Listing WHERE username = '$username'")or die( mysqli_error($con));
$solutions = array();
while ($row = mysqli_fetch_assoc($result))
        {

          print $solutions[0]=$row['Listingname']."</br>";
        }

Solution

I think i know what you mean.
That when you have this:

while ($row = mysqli_fetch_assoc($result))
{    
   echo '<a href="/names/'.$row['Listingname'].'">'.$row['Listingname'].'</br>';
}

That you get a list of names as a link.
Alfredo (www.MySite.com/names/Alfredo)
Sandra (www.MySite.com/names/Sandra)

And somebody clicks on a link, like Sandra. He goes to the url:

www.MySite.com/names/Sandra

And on that page, you can get the url with $_SERVER['REQUEST_URI']

$parts = explode("/", $_SERVER['REQUEST_URI']); 
$name = $parts['4'];

Example of the query can be:

"SELECT * FROM Names WHERE name = '$name'"

And than you can get the results from the url into the query to get the results of the name. That you can show on the page.



Answered By - Carl0s1z
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing