meofcourse Posted December 18, 2006 Share Posted December 18, 2006 I have several problems: 1. I'm a newbie and do not know the full power of the language yet (Started web programing in my free time about a month ago)2. I am getting data from MySQL database using PEAR. This data are documents of variable lengths. I have a messy script to generate tables using the data returned from the query. (This is for an admin backend page to add content dynamically). Here is the script, I'd like to neaten it up considerably:[code]<?php$sql = "SELECT * FROM `articles`";$sqlresult = sql_select($sql);$id = null;$row = null;print("<table border =\"1\" width =\"400\">");while($success = $sqlresult->fetchInto($row)){ if(DB::isError($success)){ die($success->getMessage()); } print("<TR><TH>Date Posted: ".$row['article_date']." </TH><TH>Location: ".$row['location']."</TH><TH align = \"right\">Posted By: ".$row['article_user']."</th><Th><form enctype=\"multipart/form-data\" action=\"article_edit.php\" method=\"POST\"><input type=\"hidden\" name=\"location\" value=".$row['location']."><input type=\"hidden\" name=\"article_id\" value=".$row['article_id']."><input type=\"submit\" name=\"edit_submit\" value=\"Edit\"></form></th><th><form enctype=\"multipart/form-data\" action=\"article_create.php\" method=\"POST\"><input type=\"hidden\" name=\"delete\" value=".$row['article_id']."><input type=\"submit\" name=\"delete_submit\" value=\"Delete\"></form></th></tr><TR><TH colspan=5><div style=\"overflow:auto; height:175px; width:400px\">".$row['article_body']."</div></TH></TR><tr><th colspan = 5> </th></tr>");}?></table>[/code]Ugly isn't it.3. If you notice at the end of the print line of the script there is the "<div style=" etc... what this is causing, is that th is always 175 px high even if there is only one line of text contained in the $row['article_body'].What I want is to be able to have the table dynamically expand to the size of the document like normal, but if it expands to more than 175 px it starts to scroll. Is there a way to do this?4. Other option not really what I want to do though. Could I test for the amount of lines (not string length, because it has paragraph and break lines as well) that the mysql query returns?EDIT: #3 is my primary objective, but I don't think php could help me do this except by implementing #4. Link to comment https://forums.phpfreaks.com/topic/31157-number-of-lines-returned-from-mysql-query/ Share on other sites More sharing options...
matto Posted December 18, 2006 Share Posted December 18, 2006 re your number 4mysql_num_rows() can be used to return the amount of rows from a mysql_query ;) Link to comment https://forums.phpfreaks.com/topic/31157-number-of-lines-returned-from-mysql-query/#findComment-143986 Share on other sites More sharing options...
meofcourse Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=matto link=topic=119167.msg487709#msg487709 date=1166481209]re your number 4mysql_num_rows() can be used to return the amount of rows from a mysql_query ;)[/quote]I tried your suggestion (Thanks by the way :))The problem is that I am using PEAR to do my query for me and it the mysql_num_rows() command returns "supplied arguement is not a valid MySQL result resource" Link to comment https://forums.phpfreaks.com/topic/31157-number-of-lines-returned-from-mysql-query/#findComment-143994 Share on other sites More sharing options...
meofcourse Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=meofcourse link=topic=119167.msg487717#msg487717 date=1166482093][quote author=matto link=topic=119167.msg487709#msg487709 date=1166481209]re your number 4mysql_num_rows() can be used to return the amount of rows from a mysql_query ;)[/quote]I tried your suggestion (Thanks by the way :))The problem is that I am using PEAR to do my query for me and it the mysql_num_rows() command returns "supplied arguement is not a valid MySQL result resource"[/quote]Update: I did a bit of quick research, and found the PEAR equivilent of the the command you suggested. It is $sqlresult->numRows()This is great, except its not what I want :'( I actually want the number of lines in the string returned by the mysql statement, not the number of rows in the table returned by the mysql query. Sorry for the confusion Link to comment https://forums.phpfreaks.com/topic/31157-number-of-lines-returned-from-mysql-query/#findComment-143999 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 [quote]I actually want the number of lines in the string returned by the mysql statement[/quote]Define a line. Link to comment https://forums.phpfreaks.com/topic/31157-number-of-lines-returned-from-mysql-query/#findComment-144005 Share on other sites More sharing options...
meofcourse Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=thorpe link=topic=119167.msg487728#msg487728 date=1166483042][quote]I actually want the number of lines in the string returned by the mysql statement[/quote]Define a line.[/quote]A line would be as it would be displayed in the table. Any place where there would be a <br><hr><p><li>In short any html tag that would cause a new line to occur. That is a line. :) Link to comment https://forums.phpfreaks.com/topic/31157-number-of-lines-returned-from-mysql-query/#findComment-144006 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 You could run the record through a series of calls to [url=http://php.net/substr_count]substr_count[/url] to get the total. eg;[code]<?php $breaks = array('</ br>','<p>','<li>'); foreach ($breaks as $break) { $lines += substr_count($record,$break); }?>[/code]probably not too reliable though. you would be much better off letting this div resize itself naturally but that has nothing to do with php. Link to comment https://forums.phpfreaks.com/topic/31157-number-of-lines-returned-from-mysql-query/#findComment-144020 Share on other sites More sharing options...
meofcourse Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=thorpe link=topic=119167.msg487743#msg487743 date=1166484443]You could run the record through a series of calls to [url=http://php.net/substr_count]substr_count[/url] to get the total. eg;[code]<?php $breaks = array('</ br>','<p>','<li>'); foreach ($breaks as $break) { $lines += substr_count($record,$break); }?>[/code]probably not too reliable though. you would be much better off letting this div resize itself naturally but that has nothing to do with php.[/quote]Thanks ;) Link to comment https://forums.phpfreaks.com/topic/31157-number-of-lines-returned-from-mysql-query/#findComment-144025 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.