XCVIII Posted August 13, 2012 Share Posted August 13, 2012 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/267041-echoing-specific-valueslines-from-rows/ Share on other sites More sharing options...
btherl Posted August 13, 2012 Share Posted August 13, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267041-echoing-specific-valueslines-from-rows/#findComment-1369149 Share on other sites More sharing options...
Barand Posted August 13, 2012 Share Posted August 13, 2012 With terminology like that I'm surprised anyone even attempted a reply. Quote Link to comment https://forums.phpfreaks.com/topic/267041-echoing-specific-valueslines-from-rows/#findComment-1369168 Share on other sites More sharing options...
Christian F. Posted August 14, 2012 Share Posted August 14, 2012 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". Quote Link to comment https://forums.phpfreaks.com/topic/267041-echoing-specific-valueslines-from-rows/#findComment-1369179 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.