Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Sort a Table with input from mysql

Codes here !

Moderators: macek, egami, gesf

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:

<?php
$con=mysqli_connect("localhost","root","","");
// 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']) &&
in_array($_GET['orderBy'],
$orderBy))
{
$order = $_GET['orderBy'];
}
}

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


while($row = mysqli_fetch_array($result))

{
echo "<table border='1'>
<tr>
<th><A HREF="?orderBy=title1">title1</a></th>
<th>Image</th>
<th><A HREF="?orderBy=title2">title2</A></th>
<th>Link</th>
</tr>";



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>";
}
mysqli_close($con);
?>

So, what is wrong, and have someone please the solution ? :) Thank you
ManpowerIan
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Jan 30, 2014 10:02 am

Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron