cdmafra Posted March 9, 2014 Share Posted March 9, 2014 Hello. I want to show in my website all entries from a table, but I only want to show some values in one of the DB columns: Copyright Imagem: <?php echo $row["copyright"]; ?></p> Whati I want is to show all entries for $row["copyright"], except the ones in what the value is "null". The remaining columns, I want to show all of them. Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/ Share on other sites More sharing options...
ginerjm Posted March 9, 2014 Share Posted March 9, 2014 (edited) if ($row['copyright'] <> null) echo "Copyright Imagem: " . $row['copyright'] . "</p>"; If that helps. Edited March 9, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471909 Share on other sites More sharing options...
cdmafra Posted March 9, 2014 Author Share Posted March 9, 2014 (edited) if ($row['copyright'] <> null) echo "Copyright Imagem: " . $row['copyright'] . "</p>"; If that helps. Nop, returns this error: Parse error: syntax error, unexpected ';' in /www/users/m/o/t/motorracingnews/index.php on line 117 My code in line 117: <p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT<br/>Copyright Imagem: <?php if ($row['copyright'] <> Desconhecido) echo "Copyright Imagem: " . $row['copyright'] .; ?></p> I adapted the code snippet to my design, but when I copy-paste exactly it not returns the error, but continues to show "Copyright Imagem", only not shows the $row['copyright'] Edited March 9, 2014 by cdmafra Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471910 Share on other sites More sharing options...
ginerjm Posted March 9, 2014 Share Posted March 9, 2014 FWIW, can I tell you that in my scripts I have only ONE SINGLE php start tag? No matter how large the script, that is all there ever is. What that means is I don't switch in and out of php mode to do simple little things like display a variable in the html. First I separate the majority of my html from my php logic. Second I only mingle them when I'm building things like tables or dropdowns. This allows me to avoid <? ?> and to make eminently more readable code. That said, this line needs to change for your benefit: <p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT<br/>Copyright Imagem: <?php if ($row['copyright'] <> Desconhecido) echo "Copyright Imagem: " . $row['copyright'] .; ?></p> Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471916 Share on other sites More sharing options...
cdmafra Posted March 9, 2014 Author Share Posted March 9, 2014 FWIW, can I tell you that in my scripts I have only ONE SINGLE php start tag? No matter how large the script, that is all there ever is. What that means is I don't switch in and out of php mode to do simple little things like display a variable in the html. First I separate the majority of my html from my php logic. Second I only mingle them when I'm building things like tables or dropdowns. This allows me to avoid <? ?> and to make eminently more readable code. That said, this line needs to change for your benefit: <p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT<br/>Copyright Imagem: <?php if ($row['copyright'] <> Desconhecido) echo "Copyright Imagem: " . $row['copyright'] .; ?></p> I understood... so: <?php "<p id='data'>"echo .$row['news_date'].$row['hour']. " GTM<br/>" if ($row['copyright'] <> null) echo "Copyright Imagem: " . $row['copyright'] .; "</p>"?> Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471917 Share on other sites More sharing options...
ginerjm Posted March 9, 2014 Share Posted March 9, 2014 (edited) Not at all. Something was wrong with my previous post - the corrected code didn't make it to the post New code should be: <p id="data">$news_date, $hour GMT<br/>$copyright</p> where the php vars are assigned earlier in the code. Also - this line needs to be echo'ed or included as part of a heredocs block. Edited March 9, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471918 Share on other sites More sharing options...
cdmafra Posted March 9, 2014 Author Share Posted March 9, 2014 Not at all. Something was wrong with my previous post - the corrected code didn't make it to the post New code should be: <p id="data">$news_date, $hour GMT<br/>$copyright</p> where the php vars are assigned earlier in the code. Also - this line needs to be echo'ed or included as part of a heredocs block. So if I understood, I need to define that variables ($news_date, etc.) previously, echoeing the values that I want? Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471919 Share on other sites More sharing options...
ginerjm Posted March 9, 2014 Share Posted March 9, 2014 It will help you make a cleaner line of code that may solve your error message and your desire to print/not print the copyright data Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471922 Share on other sites More sharing options...
cdmafra Posted March 9, 2014 Author Share Posted March 9, 2014 It will help you make a cleaner line of code that may solve your error message and your desire to print/not print the copyright data Thank you. Now returns me the error: "Parse error: syntax error, unexpected T_ECHO in /www/users/m/o/t/motorracingnews/index.php on line 117" <?php $news_date= echo $row['news_date']; $hour= echo $row['hour'] "GMT"; $copyright= if ($row['copyright'] <> Desconhecido) echo "Copyright Imagem: " . $row['copyright'] . ?> <p id="data"><?php $news_date $hour $copyright?></p> Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471930 Share on other sites More sharing options...
ginerjm Posted March 9, 2014 Share Posted March 9, 2014 That's because you don't know anything about writing php code. Sorry - can't help you if you can't follow my lead Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471931 Share on other sites More sharing options...
cdmafra Posted March 9, 2014 Author Share Posted March 9, 2014 (edited) That's because you don't know anything about writing php code. Sorry - can't help you if you can't follow my lead I know, otherwise it would be impossible to build a PHP-based website as I did. I am just not understanding you... Edited March 9, 2014 by cdmafra Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471942 Share on other sites More sharing options...
ginerjm Posted March 10, 2014 Share Posted March 10, 2014 (edited) I am positive that you did NOT "build a php website" as you said. "Building" implies that you wrote it. Judging by the last post you made showing your coding of my proposed solution tells me you don't have a clue. Edited March 10, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471961 Share on other sites More sharing options...
Solution cdmafra Posted March 10, 2014 Author Solution Share Posted March 10, 2014 (edited) I am positive that you did NOT "build a php website" as you said. "Building" implies that you wrote it. Judging by the last post you made showing your coding of my proposed solution tells me you don't have a clue. I usually take a long time to understand somethings in areas as PHP or Matemathics. Meanwhile, I saw one thing wrong in your first code snippet integrated with my existing code, and so in that way this works. The period for concatenation after .$row['copyright'] was wrong... <p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT<br/>Copyright Imagem: <?php if ($row['copyright'] <> Desconhecido) echo "Copyright Imagem: " . $row['copyright'] ; ?></p> Edited March 10, 2014 by cdmafra Quote Link to comment https://forums.phpfreaks.com/topic/286820-php-show-only-some-column-entries-mysql-db/#findComment-1471995 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.