Bitcoin Forum
October 10, 2024, 11:23:58 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Looking for a SQL Query person who's good with PHP as well.  (Read 391 times)
MoreBloodWine (OP)
Legendary
*
Offline Offline

Activity: 1064
Merit: 1001


View Profile
January 05, 2015, 01:18:15 PM
 #1

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:
				<td>
"age"
</td>

<td>
"added"
</td>

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.

To be decided...
mrflibblehat
Sr. Member
****
Offline Offline

Activity: 350
Merit: 250

★YoBit.Net★ 350+ Coins Exchange & Dice


View Profile
January 05, 2015, 02:43:46 PM
 #2

Does this work, cant test because I'm at work right now.

Code:
<html>
<head>
<title>SQL Statment/PHP Test</title>
</head>
<body>

<table>
<tr>
<th>
"age"
</th>

<th>
"added"
</th>
</tr>


<?php

// 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 
"<tr>"
       
echo "<td>"
       
echo $row["age"];
        
echo "</td>"
        
echo "<td>"
        
echo $row["added"];
        
echo "</td>"
        
echo "</tr>"
    
}
?>


</table>
</body>
</html>


MoreBloodWine (OP)
Legendary
*
Offline Offline

Activity: 1064
Merit: 1001


View Profile
January 05, 2015, 03:29:07 PM
 #3

Does this work, cant test because I'm at work right now.

Code:
<html>
<head>
<title>SQL Statment/PHP Test</title>
</head>
<body>

<table>
<tr>
<th>
"age"
</th>

<th>
"added"
</th>
</tr>


<?php

// 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 
"<tr>"
       
echo "<td>"
       
echo $row["age"];
        
echo "</td>"
        
echo "<td>"
        
echo $row["added"];
        
echo "</td>"
        
echo "</tr>"
    
}
?>


</table>
</body>
</html>

Didn't work but found something that did. Locking thread but still willing to toss you a lil something for trying, PM me your address. Wont be anything big BTW.

To be decided...
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!