Jump to content

PHP View Info from Database


vigiw

Recommended Posts

[code=php:0]
echo "<tr><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>-</font></td>";
echo "<td align=center bgcolor=gray><font face=Arial color=#FFFFFF>INACTIVE</font></td></tr>";
}

}
elseif (mysql_num_rows($q) > 0)
[/code]

I'm not sure if you needed that bracket at the end of your echoing. Just remove the either one of the closing brackets.
Link to comment
Share on other sites

Perhaps my old code, updated to just before the last post I made with the full code, is better.

I was just trying to integrate what I had with these suggestions, I'm not sure what to make of the:


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/vigilant/public_html/forecast/swc/view.php on line 4

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/vigilant/public_html/forecast/swc/view.php on line 69

Errors, though.
Link to comment
Share on other sites

Ok, Here's lines 67 through 71:

[code]echo "<td align=center bgcolor=red><font face=Arial color=#FFFFFF>VERY LIKELY</font></td>";
}
") or die(mysql_error());
if(mysql_num_rows($q) == 0) { echo "<tr><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>-</font></td><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>INACTIVE</font></td></tr>"; }
?>[/code]

That is the very end of the "if the table is full" section transitioning to "if it is empty" section.

The second-to-last line on that page (line 70, the if statement line)

is generating the same error:


Parse error: parse error, unexpected '>' in /home/vigilant/public_html/forecast/swc/view.php on line 70
Link to comment
Share on other sites

Oh I figured the end of the first section, makes more sense now.

But, with that being changed, here's the new error message:

Parse error: parse error, unexpected $ in /home/vigilant/public_html/forecast/swc/view.php on line 71

here's lines 67 through 71:

[code]echo "<td align=center bgcolor=red><font face=Arial color=#FFFFFF>VERY LIKELY</font></td>";
}
if(mysql_num_rows($q) == 0) { echo "<tr><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>-</font></td><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>INACTIVE</font></td></tr>"; }
") or die(mysql_error());
?>[/code]

Line 71 is the closing PHP tag ?>

Odd!  Thanks.
Link to comment
Share on other sites

You STILL have the code in the wrong spot.

LOOK at it. Does that even make sense?
The ; character means end of line. So your next line starts with you opening a string which you never end. That is your error.
You need to understand what you are actually writing, does it make any sense to put that line there? If you just copy and paste the fixes without knowing why, you'll be stuck forever.

When he says "on the end of the query" he means the SQL query. Not the end of all your code.
Link to comment
Share on other sites

Like I said, I am a beginner with PHP.  I do not completely understand this, this is why I am asking for help with what I have done and what is not working.  I appreciate your help.

What is in the wrong spot?  Which "code"?

The query ends after the INACTIVE if statement since it is going to the same place to check to see IF it is filled or not--which is why it is under that line.
Link to comment
Share on other sites

Look at the code you posted last. Do you see anywhere where you have a string beginning a line and you never close it? A string is surrounded by quotes. Look at the line right above your closing tag. I know you are a beginner which is why you need to understand what the code means, not just let us keep fixing it for you :)

Link to comment
Share on other sites

I don't see a line not being closed.

Are you saying this:

if(mysql_num_rows($q) == 0) { echo "<tr><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>-</font></td><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>INACTIVE</font></td></tr>"; }

Should have this:

") or die(mysql_error());

..on the same line?  Or should the quote for the mysql error die line be removed?

I'm confused.  I am just using what I was suggested.. I didn't have a or die mysql_error line in there before.
Link to comment
Share on other sites

This is the code you posted.
[code]echo "<td align=center bgcolor=red><font face=Arial color=#FFFFFF>VERY LIKELY</font></td>";
}
if(mysql_num_rows($q) == 0) { echo "<tr><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>-</font></td><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>INACTIVE</font></td></tr>"; }
") or die(mysql_error());
?>[/code]

You don't see how this:
[code]") or die(mysql_error());[/code]
is not valid code? What do you think this does?
You were supposed to put that on the end of your query. Instead you put it at the end of your code.

This symbol: " starts and ends a string. So, you have a STRING being started on that line and it never ends. So php can't compile the code.

Just remove the line. I'm not trying to be rude, but you need to take a minute and read through the code and say, okay, what does this do? Is this causing the error? If I comment out this line, does the error still occur? Ok, it doesn't, so this is the line that is causing this error. Oh wait, this line doesn't make any sense.
Link to comment
Share on other sites

Hmm..

No more errors, however, if you look at it here--
http://vigilantweather.com/forecast/swc/view.php

The rest of the information is not showing up.

Progress is being made, but the information from the database is not going into the same table, or anywhere for that matter.

Here's the complete code right now:

[code]<?
include("dbaccess.php");
$q = mysql_query("SELECT * FROM `swc_alertanalysis`") or die (mysql_error());
while($row = mysql_fetch_assoc($q)) {
echo "<table border=\"1\" width=\"100%\" id=\"table3\">\n" . "<tr>\n" . "<td>Storm ID</td>" . "<td>Status</td>" . "<td>Updated</td>" . "<td>Valid On</td>" . "<td>Conditions</td>" . "<td>Location</td>" . "<td>Likelihood</td>" . "<td>Risk</td>" . "<td>Alert Mode Consideration</td></tr>" . "<tr><td>1</td>";
}
$q = mysql_query("SELECT * FROM `swc_alertanalysis`") or die (mysql_error());
while($row = mysql_fetch_assoc($q)) {
if ($status == 'active')
{
echo "<td bgcolor=red>ACTIVE</td>";
}
elseif ($status == 'watching')
{
echo "<td bgcolor=#00FFFF>WATCHING</td>";
}
if ($likelihood == 'THREAT')
{
echo "<td bgcolor=aqua><font face=Arial color=#000000>THREAT</td></font>";
}
elseif ($likelihood == 'POSSIBLE')
{
echo "<td align=center bgcolor=blue><font face=Arial color=#FFFFFF>POSSIBLE</font></td>";
}
elseif ($likelihood == 'LIKELY')
{
echo "<td align=center bgcolor=orange><font face=Arial color=#FFFFFF>LIKELY</font></td>";
}
elseif ($likelihood == 'VERY LIKELY')
{
echo "<td align=center bgcolor=red><font face=Arial color=#FFFFFF>VERY LIKELY</font></td>";
}

if ($risk == 'LOW')
{
echo "<td bgcolor=aqua><font face=Arial color=#000000>LOW</td></font>";
}
elseif ($risk == 'MODERATE')
{
echo "<td align=center bgcolor=blue><font face=Arial color=#FFFFFF>MODERATE</font></td>";
}
elseif ($risk == 'HIGH')
{
echo "<td align=center bgcolor=orange><font face=Arial color=#FFFFFF>HIGH</font></td>";
}
elseif ($risk == 'EXTREME')
{
echo "<td align=center bgcolor=red><font face=Arial color=#FFFFFF>EXTREME</font></td>";
}

if ($consideration == 'UNLIKELY')
{
echo "<td bgcolor=gray><font face=Arial color=#FFFFFF>UNLIKELY</td></font>";
}
elseif ($consideration == 'POSSIBLE')
{
echo "<td align=center bgcolor=aqua><font face=Arial color=#000000>POSSIBLE</font></td>";
}
elseif ($consideration == 'IN CONSIDERATION')
{
echo "<td align=center bgcolor=blue><font face=Arial color=#FFFFFF>IN CONSIDERATION</font></td>";
}
elseif ($consideration == 'LIKELY')
{
echo "<td align=center bgcolor=orange><font face=Arial color=#FFFFFF>LIKELY</font></td>";
}
elseif ($consideration == 'VERY LIKELY')
{
echo "<td align=center bgcolor=red><font face=Arial color=#FFFFFF>VERY LIKELY</font></td>";
}
if(mysql_num_rows($q) == 0){ echo "<tr><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>-</font></td><td align=center bgcolor=gray><font face=Arial color=#FFFFFF>INACTIVE</font></td></tr>"; }
?>[/code]

Is there anything I may have missed, I have searched and searched around there and can't find anything that may be preventing this.

Thanks everyone!
Link to comment
Share on other sites

You're calling the query twice. Remove the first one.

[code]
echo "<table border=\"1\" width=\"100%\" id=\"table3\">\n" . "<tr>\n" . "<td>Storm ID</td>" . "<td>Status</td>" . "<td>Updated</td>" . "<td>Valid On</td>" . "<td>Conditions</td>" . "<td>Location</td>" . "<td>Likelihood</td>" . "<td>Risk</td>" . "<td>Alert Mode Consideration</td></tr>" . "<tr><td>1</td>";
$q = mysql_query("SELECT * FROM `swc_alertanalysis`") or die (mysql_error());
while($row = mysql_fetch_assoc($q)) {
    //Is status a field in your table? If so...
    $status = $row['status'];
    if ($status == 'active') {
        ...
[/code]
Now you need to know WHY.

Please go read some of the tutorials. Seriously. They're written for a reason.

You can clean up your html several ways. First, you don't need to keep concatenating strings. You can have one long string.
You can even close your PHP and just write HTML.

[code]
<table border="1" width="100%" id="table3">
  <tr>
      <td>Storm ID</td>
      <td>Status</td>
      <td>Updated</td>
      <td>Valid On</td>
      <td>Conditions</td>
      <td>Location</td>
      <td>Likelihood</td>
      <td>Risk</td>
      <td>Alert Mode Consideration</td>
  </tr>
<?
$q = mysql_query("SELECT * FROM `swc_alertanalysis`") or die (mysql_error());
while($row = mysql_fetch_assoc($q)) {
    //Is status a field in your table? If so...
    $status = $row['status'];
    if ($status == 'active') {
        ...
[/code]
Link to comment
Share on other sites

[code]
<?php //start php
//database connection.

include("dbaccess.php");

//database query.

$q = mysql_query("SELECT * FROM `swc_alertanalysis`") or die (mysql_error());

//while loop.

while($row = mysql_fetch_assoc($q)) {

?>//end php.

<table border="1" width="100%" id="table3">
<tr>
<td>Storm ID</td>
<td>Status</td>
<td>Updated</td>
<td>Valid On</td>
<td>Conditions</td>
<td>Location</td>
<td>Likelihood</td>
<td>Risk</td>
<td>Alert Mode Consideration</td>
</tr>
<tr>
<td>1</td>

<?php //start php

if ($status == 'active') {
?>//end php
<td bgcolor="red">ACTIVE</td>
<?php //start php
}
elseif ($status == 'watching')
{
?>//end php
<td bgcolor="#00FFFF">WATCHING</td>
<?php //start php
}

if ($likelihood == 'THREAT')
{
?>//end php
<td bgcolor="aqua"><font face="Arial" color="#000000">THREAT</td></font>
<?php // start php
}
elseif ($likelihood == 'POSSIBLE')
{
?>//end php
<td align="center" bgcolor="blue"><font face="Arial" color="#FFFFFF">POSSIBLE</font></td>
<?php //start php
}
elseif ($likelihood == 'LIKELY')
{
?>//end php
<td align="center" bgcolor="orange"><font face="Arial" color="#FFFFFF ">LIKELY</font></td>
<?php // start php
}
elseif ($likelihood == 'VERY LIKELY') {
?>//end php
<td align="center" bgcolor="red"><font face="Arial" color="#FFFFFF">VERY LIKELY</font></td>
<?php //start php
}
elseif ($risk == 'LOW')
{
?> //end php
<td bgcolor="aqua"><font face="Arial color="#000000">LOW</td></font>
<?php //start php
}
elseif ($risk == 'MODERATE')
{
?> //end php
<td align="center" bgcolor="blue"><font face="Arial" color="#FFFFFF">MODERATE</font></td>
<?php //start php
}
elseif ($risk == 'HIGH')
{
?> //end php
<td align="center" bgcolor="orange"><font face="Arial" color="#FFFFFF">HIGH</font></td>
<?php //start php
}
elseif ($risk == 'EXTREME')
{
?> //end php

<td align="center" bgcolor="red"><font face="Arial" color="#FFFFFF">EXTREME</font></td>";
<?php //start php
}

if ($consideration == 'UNLIKELY')
{
?> //end php
<td bgcolor="gray"><font face="Arial" color="#FFFFFF">UNLIKELY</td></font>
<?php // start php
}
elseif ($consideration == 'POSSIBLE')
{
?> //end php
<td align="center" bgcolor="aqua"><font face="Arial" color="#000000">POSSIBLE</font></td>
<?php // start php
}
elseif ($consideration == 'IN CONSIDERATION')
{
?>// end php
<td align="center" bgcolor="blue"><font face="Arial" color="#FFFFFF">IN CONSIDERATION</font></td>
<?php // start php
}
elseif ($consideration == 'LIKELY')
{
?>// end php
<td align="center" bgcolor=orange><font face="Arial" color="#FFFFFF">LIKELY</font></td>
<?php //start php
}
elseif ($consideration == 'VERY LIKELY')
{
?>//end php
<td align="center" bgcolor="red"><font face="Arial" color="#FFFFFF">VERY LIKELY</font></td>
<?php // start php
}
if(mysql_num_rows($q) == 0){
?>
<tr><td align="center" bgcolor="gray"><font face="Arial" color="#FFFFFF">-</font></td><td align="center" bgcolor="gray"><font face="Arial" color="#FFFFFF">INACTIVE</font></td></tr>
<?

}

?> //end while loop.
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.