Author

Topic: Looking for a SQL Query person who's good with PHP as well. (Read 399 times)

legendary
Activity: 1064
Merit: 1001
sr. member
Activity: 350
Merit: 250
★YoBit.Net★ 350+ Coins Exchange & Dice
Does this work, cant test because I'm at work right now.

Code:


SQL Statment/PHP Test












// Database Variables
$host 'localhost'
$username 'User';
$passphrase 'Pass';
$database 'database';

// Connect To Database
$connection = new mysqli($host$username$passphrase$database);

// Die if Connection Error
if ($connection->connect_error) {
    die(
"Connection failed: " $connection->connect_error);
}

// SQL Select statment
$sqlquery "SELECT age, added FROM cats";

$queryresult $connection->query($sqlquery);

if (
$queryresult->num_rows 0) {
    while(
$row $queryresult->fetch_assoc()) {

        echo 
"
"
        echo ""
         echo ""
        echo ""
    }
?>


"age"

"added"
"
        echo $row["age"];
        
echo "
"
         echo $row["added"];
        
echo "




legendary
Activity: 1064
Merit: 1001
Can pay a small bounty upon the successful test of code on my server. I would hope my trust would show me to be an honest person... please check out feedback from haploid23.

Ok, so I already have the connection bit down that connects to the DB and can select it successfully. I need a query that will choose table "cats", now in this table "cats" are two rows... "age" and "added".

Well, lets say that in table "cats" we have 5 rows which look as follows...

ageadded
1212345
1412345
912345
1212345
1812345

This is also where the PHP help comes in. The query I need would read this info and the PHP put it in a foreach type of thing so the HTML table data shows each item, like the "mock" table seen above. Basically I just want to pull the info from DB cats and show it in an HTML table.

I just need the foreach thing written for me in PHP that displays the pulled DB info in the table td's.

Code:

"age"



"added"

I know I probably could have said this all in a much simpler way but I haven't slept yet and wanted to get this posted before I lose what little brain activity I have left lol

Edit: It should order descending by the "added" row so the newest entry is always the first td.

Ty.
Jump to: