Sort a Table with input from mysql

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jan 30, 2014 10:02 am

Sort a Table with input from mysql

Postby ManpowerIan » Thu Jan 30, 2014 10:10 am

So - Hi. New here, and new with php. Need help :) At the moment i try to learn to sort a table, where users can choose how to sort it. I have found some script online saying how, but I really dont know where to put it in, since it obviously not works :) Here is the script:

// Check connection
if (mysqli_connect_errno())
echo "Failed to connect to MySQL: " . mysqli_connect_error();
$orderBy = array('title1','title2');
$order = 'PID';
if (isset($_GET['orderBy']) &&
$order = $_GET['orderBy'];

$result = mysqli_query($con,"SELECT * FROM aTable ORDER BY ".$order);

while($row = mysqli_fetch_array($result))

echo "<table border='1'>
<th><A HREF="?orderBy=title1">title1</a></th>
<th><A HREF="?orderBy=title2">title2</A></th>

echo "<tr>";
echo "<td>" . $row['Title1'] . "</td>";
echo "<td><IMG SRC='". $row['Image']."'></td>";
echo "<td>" . $row['Title2'] . "</td>";
echo "<td><A HREF='http://" . $row['Link'] . "'>Link</A> </td>";
echo "</tr><br>";
echo "</table>";

So, what is wrong, and have someone please the solution ? :) Thank you

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 3 guests