Echoing specific values/lines from rows

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

This does not make sense (you may need to revise your wording). In MySQL terminology, the term “row” is used to describe an entry in a database table. It is possible that you mean “column”, which refers to a field name in your table. “Field” is for a single cell. There is no such thing as a “line” object in MySQL. You may mean that you have a field with contents that are separated by new line characters. A “row” does not split information by “lines”, it splits information into “fields”. What is confusing is that we can’t tell if you have 7 different columns in your table, or if you have one column with data that is split into 7 lines. In either case, we don’t know the column names. Furthermore, in your SQL statement it looks like your table is called “info” and you also have a column in that table called “info” - confusing. Also confusing is that you are selecting all rows that have info=$info… which is redundant. Why would you need to fetch that data when you already have it stored in $info? My guess is that you didn’t actually test the code you submitted, because if you had it would not have worked. The most glaring evidence of this is the fact that you don’t have a $erg=mysql_query($sql); line. Simplifying your code so that we can troubleshoot more easily is a great idea, but you really need to test it before submitting. In any case, I have included below a routine that will output the lines that don’t start with a $ symbol from a string containing several lines of data. Maybe you can use it, maybe not.
[php]$var=“Font-Family
Font-Weight
Font-Color
Street
City
$Background-Color
$Phone-number”; // set up a variable with the data you (may) be trying to parse - for example’s sake only
$t=explode("\n",str_replace("\r\n","\n",$var));
foreach($t as $k=>$v)if(@$v[0]!="$")echo $v."\n";
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service