PHP Tables
#1
Posted 09 January 2012 - 08:10 PM
So basically if there is no data available from a certain column then the table row will not be displayed.
If that's possible could someone point me in the right direction.
Sorry if i've not explained that very well.
#2
Posted 09 January 2012 - 08:26 PM
WHERE `column_name` IS NOT NULL
to your query
#3
Posted 09 January 2012 - 08:47 PM
Jay Gilford, on 09 January 2012 - 08:26 PM, said:
WHERE `column_name` IS NOT NULL
to your query
Thanks for the reply, I understand what your saying there. How do I go about adding my HTML table into the PHP script? Just include an echo to each line?
#4
Posted 09 January 2012 - 09:32 PM
Lee_K, on 09 January 2012 - 08:47 PM, said:
<?php echo "<table>"; echo "<tr>"; echo "<td></td>"; echo "</tr>"; echo "</table>"; ?>
This post has been edited by webdesigner93: 09 January 2012 - 09:32 PM
#5
Posted 09 January 2012 - 10:15 PM
What I have is:
echo "<tr class='DarkPink'>";
echo "<td>'TEXT TO BE DISPLAYED'</td>";
echo "<td>'TEXT TO BE DISPLAYED'</td>";
echo "<td>'$row['COL 1']</td>";
echo "<td><a href="WEBSITE URL HERE" rel="nofollow"></a></td>";
Is that right?
Also, where would you recommend for learning PHP. I have picked up some of the basics and stuff but would like to take it further!
This post has been edited by Lee_K: 09 January 2012 - 10:19 PM
#6
Posted 09 January 2012 - 10:30 PM
Lee_K, on 09 January 2012 - 10:15 PM, said:
What I have is:
echo "<tr class='DarkPink'>";
echo "<td>'TEXT TO BE DISPLAYED'</td>";
echo "<td>'TEXT TO BE DISPLAYED'</td>";
echo "<td>'$row['COL 1']</td>";
echo "<td><a href="WEBSITE URL HERE" rel="nofollow"></a></td>";
Is that right?
Also, where would you recommend for learning PHP. I have picked up some of the basics and stuff but would like to take it further!
you need to escape your double quotes here
echo "<td><a href="WEBSITE URL HERE" rel="nofollow"></a></td>";or your gonna get an error you can escape using a slash like this
echo "<td><a href=\"WEBSITE URL HERE\" rel=\"nofollow\"></a></td>";or just use single quotes like this
echo "<td><a href='WEBSITE URL HERE' rel='nofollow'></a></td>";
thenewboston.org is a good place to start they have around 200 php videos
#7
Posted 09 January 2012 - 11:01 PM
#8
Posted 10 January 2012 - 12:35 AM
Lee_K, on 09 January 2012 - 08:47 PM, said:
You can use PHP to generate the table, but really speaking you should save all your results as an array, and pass them to a view to iterate over. If you've never looked into MVC I would highly recommend looking into the process of it
#9
Posted 10 January 2012 - 01:37 AM
You mentioned the: WHERE `column_name` IS NOT NULL to stop my table row from appearing...
So what I have is:
SELECT * FROM `tablename` WHERE `product_id` = '826' AND `COL 3` IS NOT NULL LIMIT 1
But it doesn't seem to work?
[EDIT]: If '826' didn't exist in the database would that equal to NULL? All it seems to do is leaves an empty space where that column data should be. But what I want to do is remove the full row?
I know these questions are probably just basic things to anyone who knows a thing or two about PHP and I do try to read up as much as I can but sometimes it's just a lot quicker to ask someone. So thanks guys!
This post has been edited by Lee_K: 10 January 2012 - 01:51 AM
#10
Posted 10 January 2012 - 02:11 AM
Something like.
$sql = "SELECT * FROM `tablename` WHERE `product_id` = '826' AND `COL 3` = 'something'";
$result = mysql_query($sql);
$nums = mysql_num_rows($result);
if($nums > 0) //check if there is a row (over 0 means there is)
{
while($row = mysql_fetch_array($result))
{
echo "<tr class='DarkPink'>";
echo "<td>TEXT TO BE DISPLAYED</td>";
echo "<td>TEXT TO BE DISPLAYED</td>";
echo "<td>".$row['COL 1']."</td>";
echo "<td><a href='WEBSITE URL HERE' rel='nofollow'>LINK</a></td>"
echo "</tr>";
}
}
else {
echo "no results found";
}
This post has been edited by Samus: 10 January 2012 - 02:13 AM
#11
Posted 10 January 2012 - 02:56 PM
#12
Posted 10 January 2012 - 06:15 PM
I know how to link to multiple tables to order in ASC. But what I have is something like, WHERE `COL 1` = '826'
But I only want that 826 to apply for 1 table, then have another number for the next table. Basically so that if '826' appeared in the 2nd table, the data wouldn't be pulled out... Does that make sense?
#13
Posted 10 January 2012 - 08:25 PM
Lee_K, on 10 January 2012 - 06:15 PM, said:
I know how to link to multiple tables to order in ASC. But what I have is something like, WHERE `COL 1` = '826'
But I only want that 826 to apply for 1 table, then have another number for the next table. Basically so that if '826' appeared in the 2nd table, the data wouldn't be pulled out... Does that make sense?
Yeah, you'd only need to modify the query per table, you'd probs wanna make this into a function to stop repetitive code.
using my code snippet above:
function output_tables($COL3)
{
$sql = "SELECT * FROM `tablename` WHERE `COL 3` = '$COL3'";
$result = mysql_query($sql);
$nums = mysql_num_rows($result);
if($nums > 0) //check if there is a row (over 0 means there is)
{
while($row = mysql_fetch_array($result))
{
echo "<tr class='DarkPink'>";
echo "<td>TEXT TO BE DISPLAYED</td>";
echo "<td>TEXT TO BE DISPLAYED</td>";
echo "<td>".$row['COL 3']."</td>";
echo "<td><a href='WEBSITE URL HERE' rel='nofollow'>LINK</a></td>"
echo "</tr>";
}
}
else {
echo "no results found";
}
}
Then use it like:
output_tables('826');
<br/>
output_tables('821');
where 826 & 821 are the values for COL 3
#14
Posted 10 January 2012 - 11:57 PM
This post has been edited by Lee_K: 11 January 2012 - 12:00 AM
#16
Posted 11 January 2012 - 01:53 AM
Basically what I have is:
$sql = "SELECT * FROM `Retailer` WHERE `product_id` = '826' AND `price` IS NOT NULL";
$result = mysql_query($sql);
$nums = mysql_num_rows($result);
if($nums > 0) //Check if there is a row (over 0 means there is)
{
while($row = mysql_fetch_array($result))
{
echo "<table>";
echo "<tr class='DarkPink'>";
echo "<td>Retailer</td>";
echo "<td>£ $row[price]</td>";
echo "<td><a href=WEBSITEURL rel='nofollow'></a></td>";
echo "</tr>";
echo "</table>";
}
}
else {
echo "";
}
?>
Then on the next row I want to retrieve data from the same column, but from another table, and ONLY from: WHERE `product_id` = '990' AND `price` IS NOT NULL";
What I don't is it to be picking out '826' from the second table aswell.
And then once I have my 5 rows from 5 different tables, I want to be able to order them by ASC.
Apologies if this is basically what you guys have already said, it's late and this thing has me well puzzled now!
This post has been edited by Lee_K: 11 January 2012 - 01:54 AM
#17
Posted 11 January 2012 - 04:58 AM
Lee_K, on 11 January 2012 - 01:53 AM, said:
Basically what I have is:
$sql = "SELECT * FROM `Retailer` WHERE `product_id` = '826' AND `price` IS NOT NULL";
$result = mysql_query($sql);
$nums = mysql_num_rows($result);
if($nums > 0) //Check if there is a row (over 0 means there is)
{
while($row = mysql_fetch_array($result))
{
echo "<table>";
echo "<tr class='DarkPink'>";
echo "<td>Retailer</td>";
echo "<td>£ $row[price]</td>";
echo "<td><a href=WEBSITEURL rel='nofollow'></a></td>";
echo "</tr>";
echo "</table>";
}
}
else {
echo "";
}
?>
Then on the next row I want to retrieve data from the same column, but from another table, and ONLY from: WHERE `product_id` = '990' AND `price` IS NOT NULL";
What I don't is it to be picking out '826' from the second table aswell.
And then once I have my 5 rows from 5 different tables, I want to be able to order them by ASC.
Apologies if this is basically what you guys have already said, it's late and this thing has me well puzzled now!
Use my function above. Edit the SQL to show what webdesigner93 posted. And simply just call the functions.
You wouldn't need to re echo them, because the function is already doing that.
You'd have to include the whole written function at the top of your page, or in another file which is included/required in that page. And you just call the function five times.
output_tables('826');
<br/>
output_tables('824');
<br/>
output_tables('822');
<br/>
output_tables('820');
<br/>
output_tables('818');
This post has been edited by Samus: 11 January 2012 - 05:01 AM
#18
Posted 11 January 2012 - 11:22 AM
#19
Posted 12 January 2012 - 12:01 AM
How come I can't make function output_tables($COL3) a number where COL3 is? I copied the code as above and edited it to suit but guess i've gone wrong somewhere?
#20
Posted 12 January 2012 - 12:15 AM
Lee_K, on 12 January 2012 - 12:01 AM, said:
How come I can't make function output_tables($COL3) a number where COL3 is? I copied the code as above and edited it to suit but guess i've gone wrong somewhere?
mmm u mean make output_tables out put an integer value instead of a string?
#21
Posted 12 January 2012 - 12:43 AM
#22
Posted 12 January 2012 - 12:45 AM
Lee_K, on 12 January 2012 - 12:43 AM, said:
despite what some people say html and css is not a real programming language but a way of laying out things, so thats why haha
#23
Posted 12 January 2012 - 01:02 AM
#24
Posted 12 January 2012 - 06:39 PM
I can get it working to display 1 row, using 1 of the functions but what I need is to display 5 different rows from 5 different tables. Which would mean using multiple functions? And for some reason when I try to use more than 1, the page just stays blank>
This post has been edited by Lee_K: 12 January 2012 - 06:57 PM
#25
Posted 12 January 2012 - 11:08 PM
This post has been edited by Lee_K: 13 January 2012 - 12:07 AM
#26
Posted 14 January 2012 - 06:48 PM
$this->load->library('table');
$query = $this->db->query("SELECT * FROM the_table");
echo $this->table->generate($query);
#31
Posted 15 January 2012 - 12:02 AM
Thanks for the help in the meantime though, I have actually learnt a fair bit from this!
This post has been edited by Lee_K: 15 January 2012 - 12:05 AM
#32
Posted 15 January 2012 - 01:51 AM
Lee_K, on 15 January 2012 - 12:02 AM, said:
Thanks for the help in the meantime though, I have actually learnt a fair bit from this!
Depends on your time, depends on your resources, depends on your dedication and also depends how fast you're able to understand the concept of particular features.
#33
Posted 16 January 2012 - 05:49 PM
Basically how can I alter this to join multiple tables together and also display it using the LIKE term:
function output_tables($COL3)
{
$sql = "SELECT * FROM `tables 1. 2 and 3` WHERE `COL 3` = '$COL3'"; <----- I want this to be WHERE `COL 3` LIKE 'xyz'
$result = mysql_query($sql);
$nums = mysql_num_rows($result);
if($nums > 0) //check if there is a row (over 0 means there is)
{
while($row = mysql_fetch_array($result))
{
echo "<tr class='DarkPink'>";
echo "<td>TEXT TO BE DISPLAYED</td>";
echo "<td>TEXT TO BE DISPLAYED</td>";
echo "<td>".$row['COL 3']."</td>";
echo "<td><a href='WEBSITE URL HERE' rel='nofollow'>LINK</a></td>"
echo "</tr>";
}
}
else {
echo "no results found";
}
}So then I can recall it sort of like:
output_tables('LIKE XYZ');
This post has been edited by Lee_K: 16 January 2012 - 05:50 PM
Help

















