Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Help me with this code please

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Help me with this code please

Postby matjam69 » Thu Jun 27, 2013 2:58 pm

I'm new to php and have an assignment to display a table that I query from a database then on the click of a button the results are reversed. So if the table was 1 column with values A, B, C it would reverse on button click to show C, B, A.

Here is the code I have so far which displays the original table:

<?php

$con=mysqli_connect("localhost","root","","letters");

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM myLetters ORDER BY DESC");

echo "<table border='1'>
<tr>
<th>ABC</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ABC'] . "</td>";
$values = array();
array_push
echo "</tr>";
}
echo "</table>";


mysqli_close($con);
?>
<button onclick="myFunction()">Click to Reverse</button>
matjam69
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 25, 2013 3:20 pm

Re: Help me with this code please

Postby johnj » Thu Jun 27, 2013 8:22 pm

remove ORDER BY DESC
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Help me with this code please

Postby matjam69 » Tue Jul 02, 2013 9:36 am

Thanks for the reply John, I figured it out with some trial and error and google.
matjam69
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 25, 2013 3:20 pm


Return to PHP coding => General

Who is online

Users browsing this forum: markolson68 and 2 guests

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