Jump to content

PHP show only some column entries MySQL DB


cdmafra

Recommended Posts

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.

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']

 

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>

 

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>"?>

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.

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?

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>

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.