marcus Posted December 24, 2006 Share Posted December 24, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147180 Share on other sites More sharing options...
ataria Posted December 24, 2006 Share Posted December 24, 2006 So...invalid HTML is okay if everything is invalid? :/It isn't "Invalid." More like "Incorrect" Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147181 Share on other sites More sharing options...
vigiw Posted December 24, 2006 Author Share Posted December 24, 2006 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 4Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/vigilant/public_html/forecast/swc/view.php on line 69Errors, though. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147182 Share on other sites More sharing options...
marcus Posted December 24, 2006 Share Posted December 24, 2006 You have an error in your querySELECT * FROM `tablename`Just do that. `$tablename.whateveryouhadhere`Then when you end the query do: ") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147183 Share on other sites More sharing options...
vigiw Posted December 24, 2006 Author Share Posted December 24, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147188 Share on other sites More sharing options...
marcus Posted December 24, 2006 Share Posted December 24, 2006 ") or die(mysql_error());You add that on the end of the query. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147189 Share on other sites More sharing options...
vigiw Posted December 24, 2006 Author Share Posted December 24, 2006 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 71here'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. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147190 Share on other sites More sharing options...
Jessica Posted December 24, 2006 Share Posted December 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147194 Share on other sites More sharing options...
vigiw Posted December 24, 2006 Author Share Posted December 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147199 Share on other sites More sharing options...
Jessica Posted December 24, 2006 Share Posted December 24, 2006 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147200 Share on other sites More sharing options...
vigiw Posted December 24, 2006 Author Share Posted December 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147201 Share on other sites More sharing options...
Jessica Posted December 24, 2006 Share Posted December 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147202 Share on other sites More sharing options...
marcus Posted December 24, 2006 Share Posted December 24, 2006 You have a SQL query on like line 2-3 of your original coding.You are selecting something from like `"$table_name" . "somethinghere"`That line, add it there. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147203 Share on other sites More sharing options...
redarrow Posted December 24, 2006 Share Posted December 24, 2006 Is this a joke or windup, i put this code in my editor and all went crazy lol.You need to learn to format html in php and then all be ok but you also need to sort all mysql problams out and you need to learn css/html/mysql/php properly ok. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147205 Share on other sites More sharing options...
vigiw Posted December 24, 2006 Author Share Posted December 24, 2006 Hmm..No more errors, however, if you look at it here--http://vigilantweather.com/forecast/swc/view.phpThe 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! Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147217 Share on other sites More sharing options...
marcus Posted December 24, 2006 Share Posted December 24, 2006 What are $likelihood and $status and stuff equaling? Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147218 Share on other sites More sharing options...
Jessica Posted December 24, 2006 Share Posted December 24, 2006 Line 9: $status - where does this variable come from? Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147219 Share on other sites More sharing options...
vigiw Posted December 24, 2006 Author Share Posted December 24, 2006 That is what I figured..But I'm not sure how to make the database fields equal $field -- and where to place what needs to be added. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147221 Share on other sites More sharing options...
Jessica Posted December 24, 2006 Share Posted December 24, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147222 Share on other sites More sharing options...
redarrow Posted December 24, 2006 Share Posted December 24, 2006 this is your html out put does it look correct to you if so then it your varables or database ok.<a href="http://freesingles.ath.cx/member_test.php">your site result</a> Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147223 Share on other sites More sharing options...
vigiw Posted December 24, 2006 Author Share Posted December 24, 2006 Oops I forgot to remove that second query.Everything without the database is OK.. I need to define my variables. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147225 Share on other sites More sharing options...
redarrow Posted December 24, 2006 Share Posted December 24, 2006 i agree you should come in and out off php with the html to clear the code up. Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147226 Share on other sites More sharing options...
redarrow Posted December 24, 2006 Share Posted December 24, 2006 [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 phpif ($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] Quote Link to comment https://forums.phpfreaks.com/topic/31742-php-view-info-from-database/page/2/#findComment-147227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.