Jump to content

PHP show only some column entries MySQL DB


Go to solution Solved by 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']

 

Edited by cdmafra

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.

Edited by ginerjm

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>

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 by cdmafra

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 by ginerjm
  • Solution

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 by cdmafra
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.