Jump to content

Recommended Posts

I have a row called info-body.

 

This row contains information split up in different lines, example:

 

Font-Family

Font-Weight

Font-Color

Street

City

$Background-Color

$Phone-number

 

Now, I can echo the whole row and its then all of the info is output. But what do I need to do to echo (or fetch) only the lines that do NOT start with $ (alternatively ONLY the first 5 rows) So that when I echo the row it just outputs:

 

Font-Family

Font-Weight

Font-Color

Street

City

 

Right now I am using this too echo the whole row:

 

<?php

$sql="SELECT * FROM info WHERE info=\"".$info."\" AND page LIKE \"info-body\";";

require("connect.php");

for ($i=0;$i<mysql_num_rows($con);$i++)

{

$setter=mysql_fetch_array($erg);

echo("\n".$setter['info']."\n");

}

?>

Link to comment
https://forums.phpfreaks.com/topic/267041-echoing-specific-valueslines-from-rows/
Share on other sites

I'm a little unclear on the terminology you're using, but I think you want something like this:

 

<?php
$sql="SELECT * FROM info WHERE info=\"".$info."\" AND page LIKE \"info-body\";";
require("connect.php");
for ($i=0;$i<mysql_num_rows($con);$i++)
{
   $setter=mysql_fetch_array($erg);
   if ($setter['info']{0} != '$') {
      echo("\n".$setter['info']."\n");
   }
}
?>

 

I'm assing that $setter['info'] is the value you want to test to see if it starts with '$'.  If it's not, just change it on the line starting with "if"

 

By the way, I'm confused as to where $con and $erg come from, and why they don't match - usually you would call mysql_num_rows() and mysql_fetch_array() on the same variable.  It's also not the best code structure to have the query performed inside connect.php, which appears to be what is happening.

 

If you can post the definition of your table, and maybe some sample data from it, that would help a lot.

First off: What you have is a table named "info-body", which you're fetching multiple rows from. Each row is divided into several columns, or fields ("Font-Family", "Font-Weight" and so forth).

 

To only fetch the columns you're interested in, list them in the SELECT statements instead of using *; The star means "fetch all columns".

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.