lingo5 Posted December 2, 2011 Share Posted December 2, 2011 Hi, this is how I echo some results from my DB: <?php if(mysql_num_rows($execute)>0){ do{ echo " " .$result['id_cliente']. " " .$result['company_name']. " " .$result['cliente_tel']. " " ; }while($result = mysql_fetch_assoc($execute)); }else{ echo " No customer found. " ; } ?> and this echoes the results in one paragraph. I need to print the results in rows...and I need help with that. :shy:Thanks Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/ Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 <?php if(mysql_num_rows($execute)>0){ do{ echo " " .$result['id_cliente']. " " .$result['company_name']. " " .$result['cliente_tel']. " "."<br>" ; }while($result = mysql_fetch_assoc($execute)); }else{ echo " No customer found. " ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293408 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 thanks canabatz, but I mean table rows sorry. Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293413 Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 <table width="400" border="1"> <tr> <td>client</td> <td>company name</td> <td>Phone</td> </tr> <?php if(mysql_num_rows($execute)>0){ do{ }while($result = mysql_fetch_assoc($execute)); ?> <tr> <td><?=$result['id_cliente'] ?></td> <td><?=$result['company_name'] ?></td> <td><?=$result['cliente_tel']?></td> </tr> <? }else{ echo " No customer found. " ; } ?> </table> try that , i hope this is what you want Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293415 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 thanks again,,,now a table prints with column headers...but empty rows Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293418 Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 try that: <table width="400" border="1"> <tr> <td>client</td> <td>company name</td> <td>Phone</td> </tr> <?php if(mysql_num_rows($execute)>0){ while($result = mysql_fetch_assoc($execute)); { ?> <tr> <td><?=$result['id_cliente'] ?></td> <td><?=$result['company_name'] ?></td> <td><?=$result['cliente_tel']?></td> </tr> <? } }else{ echo " No customer found. " ; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293419 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 nope...no results displayed, just column headers Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293420 Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 try this: <table width="400" border="1"> <tr> <td>client</td> <td>company name</td> <td>Phone</td> </tr> <?php if(mysql_num_rows($execute)>0){ while($result = mysql_fetch_assoc($execute)); { ?> <tr> <td><?php echo $result['id_cliente']; ?></td> <td><?php echo $result['company_name']; ?></td> <td><?php echo $result['cliente_tel'];?></td> </tr> <? } }else{ echo " No customer found. " ; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293421 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 sorry but still no change... Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293423 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 This is the complete code: /* Get the letter user clicked on and assign it a variable called $sort */ $sort = $_REQUEST['letter']; /* Let's check if variable $sort is empty. If it is we will create a query to display all customers alphabetically ordered by last name. */ if($sort == ""){ $qry= "SELECT * FROM myDatabase.t_clientes ORDER BY company_name ASC " ; }else{ /* if varible $sort is not empty we will create a query that sorts out the customers by their last name, and order the selected records ascendingly. */ $qry = "SELECT * FROM myDatabase.t_clientes WHERE company_name LIKE '$sort%' ORDER BY company_name ASC" ; } /* Notice the use of '%' wilde card in the above query "LIKE '$sort%'". */ //next step is to execute the query. $execute = mysql_query($qry) or die(mysql_error()); /* Before we display results let's create our alphabetical navigation. for ($i = 65; $i < 91; $i++) { printf('<a href="%s?letter=%s">%s</a> | ', $PHP_SELF, chr($i), chr($i)); } echo " " ; /* now we are ready to display the results. if(mysql_num_rows($execute)>0){ do{ echo " " .$result['id_cliente']. " " .$result['company_name']. " " .$result['cliente_tel']. " " ; }while($result = mysql_fetch_assoc($execute)); }else{ echo " No customer found. " ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293432 Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 please show the all code to see where the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293433 Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 i dont see any thing wrong , jus a missing */ in your code. try this one again: <?php /* Get the letter user clicked on and assign it a variable called $sort */ $sort = $_REQUEST['letter']; /* Let's check if variable $sort is empty. If it is we will create a query to display all customers alphabetically ordered by last name. */ if($sort == ""){ $qry= "SELECT * FROM myDatabase.t_clientes ORDER BY company_name ASC " ; }else{ /* if varible $sort is not empty we will create a query that sorts out the customers by their last name, and order the selected records ascendingly. */ $qry = "SELECT * FROM myDatabase.t_clientes WHERE company_name LIKE '$sort%' ORDER BY company_name ASC" ; } /* Notice the use of '%' wilde card in the above query "LIKE '$sort%'". */ //next step is to execute the query. $execute = mysql_query($qry) or die(mysql_error()); /* Before we display results let's create our alphabetical navigation. for ($i = 65; $i < 91; $i++) { printf('<a href="%s?letter=%s">%s</a> | ', $PHP_SELF, chr($i), chr($i)); } echo " " ; /* now we are ready to display the results. */ ?> <table width="400" border="1"> <tr> <td>client</td> <td>company name</td> <td>Phone</td> </tr> <?php if(mysql_num_rows($execute)>0){ while($result = mysql_fetch_assoc($execute)); { ?> <tr> <td><?php echo $result['id_cliente']; ?></td> <td><?php echo $result['company_name']; ?></td> <td><?php echo $result['cliente_tel'];?></td> </tr> <? } }else{ echo " No customer found. " ; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293439 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 no...not printing any results...weird Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293457 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 This is very weird...the script works perfect without the table rows. Can anyone spot what I'm doing wrong? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293517 Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 from your first code: <?php if(mysql_num_rows($execute)>0){ do{ echo " " .$result['id_cliente']. " " .$result['company_name']. " " .$result['cliente_tel']. " " ; }while($result = mysql_fetch_assoc($execute)); }else{ echo " No customer found. " ; } ?> does it display all records? or just one? how many records there is? Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293524 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 all records under one letter Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293532 Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 try that: <?php /* Get the letter user clicked on and assign it a variable called $sort */ $sort = $_REQUEST['letter']; /* Let's check if variable $sort is empty. If it is we will create a query to display all customers alphabetically ordered by last name. */ if($sort == ""){ $qry= "SELECT * FROM myDatabase.t_clientes ORDER BY company_name ASC " ; }else{ /* if varible $sort is not empty we will create a query that sorts out the customers by their last name, and order the selected records ascendingly. */ $qry = "SELECT * FROM myDatabase.t_clientes WHERE company_name LIKE '$sort%' ORDER BY company_name ASC" ; } /* Notice the use of '%' wilde card in the above query "LIKE '$sort%'". */ //next step is to execute the query. $execute = mysql_query($qry) or die(mysql_error()); /* Before we display results let's create our alphabetical navigation. for ($i = 65; $i < 91; $i++) { printf('<a href="%s?letter=%s">%s</a> | ', $PHP_SELF, chr($i), chr($i)); } echo " " ; /* now we are ready to display the results. */ ?> <table width="400" border="1"> <tr> <td>client</td> <td>company name</td> <td>Phone</td> </tr> <?php if(mysql_num_rows($execute)>0){ do{ ?> <tr> <td><?php echo $result['id_cliente']; ?></td> <td><?php echo $result['company_name']; ?></td> <td><?php echo $result['cliente_tel'];?></td> </tr> <?php }while($result = mysql_fetch_assoc($execute)); }else{ echo " No customer found. " ; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293537 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 Thanks a lot, i'm almost there...I have styled my table a bit, but for some reason I am getting an empty row at the top of ach result... Here's my code <?php /* Get the letter user clicked on and assign it a variable called $sort */ $sort = $_REQUEST['letter']; /* Let's check if variable $sort is empty. If it is we will create a query to display all customers alphabetically ordered by last name. */ if($sort == ""){ $qry= "SELECT * FROM myDatabase.t_clientes ORDER BY company_name ASC " ; }else{ /* if varible $sort is not empty we will create a query that sorts out the customers by their last name, and order the selected records ascendingly. */ $qry = "SELECT * FROM myDatabase.t_clientes WHERE company_name LIKE '$sort%' ORDER BY company_name ASC" ; } /* Notice the use of '%' wilde card in the above query "LIKE '$sort%'". */ //next step is to execute the query. $execute = mysql_query($qry) or die(mysql_error()); <td width="551" align="left" nowrap="nowrap" class="UsuarioNombreHeader"> <?php for ($i = 65; $i < 91; $i++) { printf('<a href="%s?letter=%s">%s</a> | ', $PHP_SELF, chr($i), chr($i)); } echo " " ; //print t alphabet */?> </td> <table width="850" align="center" border="0" cellpadding="5" cellspacing="0" class="BottomLine"> <tr> <td><?php if(mysql_num_rows($execute)>0){ do{?> <td width="27%" align="left" nowrap="nowrap" class="AddressTXT"><strong><?php echo $result['company_name']; ?></strong></td> <td width="20%" align="left" nowrap="nowrap" class="AddressTXT"><strong>tel.<?php echo $result['cliente_tel']; ?></strong></td> <td width="27%" align="left" nowrap="nowrap" class="AddressTXT"><?php echo $result['cliente_email'];?></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_sendmail.php?id_cliente=<?php echo $result['id_cliente']; ?>"><img src="CP_img/icono_email_reducido.png" alt="" width="15" height="10" border="0" /></a></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_update.php?id_cliente=<?php echo $result['id_cliente']; ?> "onclick="return confirm('¿Seguro que desea \n ELIMINAR PERMANENTEMENTE \n <?php echo $result['company_name']; ?>?');"><img src="CP_img/icono_editar_reducido.png" width="20" height="13" border="0" /></a></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_delete.php?id_cliente=<?php echo $result['id_cliente']; ?> "onClick="return confirm('¿Seguro que desea \n ELIMINAR PERMANENTEMENTE \n <?php echo $result['company_name']; ?>?');"><img src="CP_img/icono_borrar_reducido.png" width="15" height="10" border="0" /></a></td> </tr> <?php }while($result = mysql_fetch_assoc($execute)); }else{ echo " No contacts found " ; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293586 Share on other sites More sharing options...
canabatz Posted December 2, 2011 Share Posted December 2, 2011 try now <?php /* Get the letter user clicked on and assign it a variable called $sort */ $sort = $_REQUEST['letter']; /* Let's check if variable $sort is empty. If it is we will create a query to display all customers alphabetically ordered by last name. */ if($sort == ""){ $qry= "SELECT * FROM myDatabase.t_clientes ORDER BY company_name ASC " ; }else{ /* if varible $sort is not empty we will create a query that sorts out the customers by their last name, and order the selected records ascendingly. */ $qry = "SELECT * FROM myDatabase.t_clientes WHERE company_name LIKE '$sort%' ORDER BY company_name ASC" ; } /* Notice the use of '%' wilde card in the above query "LIKE '$sort%'". */ //next step is to execute the query. $execute = mysql_query($qry) or die(mysql_error()); ?> <td width="551" align="left" nowrap="nowrap" class="UsuarioNombreHeader"> <?php for ($i = 65; $i < 91; $i++) { printf('<a href="%s?letter=%s">%s</a> | ', $PHP_SELF, chr($i), chr($i)); } echo " " ; //print t alphabet */?> </td> <table width="850" align="center" border="0" cellpadding="5" cellspacing="0" class="BottomLine"> <?php if(mysql_num_rows($execute)>0){ do{?> <tr> <td> <td width="27%" align="left" nowrap="nowrap" class="AddressTXT"><strong><?php echo $result['company_name']; ?></strong></td> <td width="20%" align="left" nowrap="nowrap" class="AddressTXT"><strong>tel.<?php echo $result['cliente_tel']; ?></strong></td> <td width="27%" align="left" nowrap="nowrap" class="AddressTXT"><?php echo $result['cliente_email'];?></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_sendmail.php?id_cliente=<?php echo $result['id_cliente']; ?>"><img src="CP_img/icono_email_reducido.png" alt="" width="15" height="10" border="0" /></a></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_update.php?id_cliente=<?php echo $result['id_cliente']; ?> "onclick="return confirm('¿Seguro que desea \n ELIMINAR PERMANENTEMENTE \n <?php echo $result['company_name']; ?>?');"><img src="CP_img/icono_editar_reducido.png" width="20" height="13" border="0" /></a></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_delete.php?id_cliente=<?php echo $result['id_cliente']; ?> "onClick="return confirm('¿Seguro que desea \n ELIMINAR PERMANENTEMENTE \n <?php echo $result['company_name']; ?>?');"><img src="CP_img/icono_borrar_reducido.png" width="15" height="10" border="0" /></a></td> </tr> <?php }while($result = mysql_fetch_assoc($execute)); }else{ echo " No contacts found " ; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293630 Share on other sites More sharing options...
lingo5 Posted December 2, 2011 Author Share Posted December 2, 2011 canabatz, many thanks for your helpbut I can't get that code to work. It must be something to do with the function that generates the letters. Anyway, I have done it a different way and it works except for one thing....I need all the records to display intially when no letter is selected and I can't seem to work that out... This is my new code: $letter= $_GET['letter']; if(!empty ($_GET['letter']) && ctype_alpha ($_GET['letter'])) { $whereclause = "company_name LIKE '".$_GET[letter]."%'"; } else { $whereclause = ""; } mysql_select_db($database_MySQLconnect, $MySQLconnect); $query_letters_RS = "SELECT id_cliente,company_name,cliente_tel,cliente_email FROM t_clientes WHERE ".$whereclause." ORDER BY company_name ASC"; $letters_RS = mysql_query($query_letters_RS, $MySQLconnect) or die(mysql_error()); $row_letters_RS = mysql_fetch_assoc($letters_RS); $totalRows_letters_RS = mysql_num_rows($letters_RS); ?> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0" > <tr> <td width="551" align="left" nowrap="nowrap" class="UsuarioNombreHeader"><div class="letters"> <span class="PClistItems"><a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=a">A</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=b">| B</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=c">| C</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=d">| D</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=e">| E</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=f">| F</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=g">| G</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=h">| H</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=i">| I</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=j">| J</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=k">| K</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=l">| L</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=m">| M</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=n">| N</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=o">| O</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=p">| P</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=q">| Q</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=r">| R</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=s">| S</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=t">| T</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=u">| U</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=v">| V</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=w">| W</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=x">| X</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=y">| Y</a> <a href="<?php echo $_SERVER["PHP_SELF"];?>?letter=z">| Z</a></span></div></td> <td align="right" nowrap="nowrap"><form action="searchFunction.php" method="post" name="formSearchClients" id="formSearchClients"> <label> <input name="searchCriteria" id="searchCriteria" type="text" onfocus="this.value='';" class="SearchFieldTXT" value="<?=CNT_TXT_ETIQCLOUD_SEARCH?>" /> <input type="hidden" name="WADbSearch1" value="Submit" /> </label> </form></td> </tr> </table></td> </tr> </table> <?php if ($totalRows_letters_RS == 0) { // Show if recordset empty ?> <table width="850" align="center" border="0" cellpadding="5" cellspacing="0" class="BottomLine"> <tr> <td height="238" align="center" nowrap="nowrap" class="NoResultsTXT">No hay contactos con la letra "<?php echo $letter;?>"</td> </tr> </table> <?php } // Show if recordset empty ?> <?php do { ?> <?php if ($totalRows_letters_RS > 0) { // Show if recordset not empty ?> <table width="850" align="center" border="0" cellpadding="5" cellspacing="0" class="BottomLine"> <tr> <td width="27%" align="left" nowrap="nowrap" class="AddressTXT"><?php echo $row_letters_RS['company_name']; ?></td> <td width="20%" align="left" nowrap="nowrap" class="AddressTXT"><strong>tel.<?php echo $row_letters_RS['cliente_tel']; ?></strong></td> <td width="27%" align="left" nowrap="nowrap" class="AddressTXT"><?php echo $row_letters_RS['cliente_email']; ?></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_sendmail.php?id_cliente=<?php echo $result['id_cliente']; ?>"><img src="CP_img/icono_email_reducido.png" alt="" width="15" height="10" border="0" /></a></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_update.php?id_cliente=<?php echo $result['id_cliente']; ?> "onclick="return confirm('¿Seguro que desea \n ELIMINAR PERMANENTEMENTE \n <?php echo $result['company_name']; ?>?');"><img src="CP_img/icono_editar_reducido.png" width="20" height="13" border="0" /></a></td> <td width="2%" align="center" class="CP_errorLoginTxt"><a href="PC_contactos_delete.php?id_cliente=<?php echo $result['id_cliente']; ?> "onclick="return confirm('¿Seguro que desea \n ELIMINAR PERMANENTEMENTE \n <?php echo $result['company_name']; ?>?');"><img src="CP_img/icono_borrar_reducido.png" width="15" height="10" border="0" /></a></td> </tr> </table> <?php } // Show if recordset not empty ?> <?php } while ($row_letters_RS = mysql_fetch_assoc($letters_RS)); ?> <table width="850" border="0" align="center" cellpadding="12" cellspacing="0" class="BottomLine"> <tr> <td width="18" align="left" nowrap="nowrap"> </td> <td width="342" align="left" nowrap="nowrap" class="AddressTXT"> </td> <td width="315" align="right" class="AddressTXT"><table width="40%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="54%" align="right" class="CP_blueTXT"><?= CNT_TXT_ETIQCLOUD_NUMBEROFPAGES?> : </td> <td width="46%" align="right" nowrap="nowrap" class="CP_blueTXT"></td> </tr> </table></td> <td width="79" align="left" nowrap="nowrap" class="CP_SiNoText"><table width="100%" border="0" cellspacing="0" cellpadding="3"> <tr> <td width="16%" align="left"><a href="javascript:history.go(-1)"><img src="CP_img/volver_button.png" alt="" width="20" height="20" border="0" /></a></td> <td width="84%" align="left" nowrap="nowrap" class="CP_blueTXT" ><a href="javascript:history.go(-1)"> <?=CNT_TXT_ETIQCLOUD_VOLVERATRAS?> </a></td> </tr> </table></td> </tr> </table> <p> </p> </body> </html> <?php mysql_free_result($letters_RS); mysql_free_result($navigation_RS); ?> Quote Link to comment https://forums.phpfreaks.com/topic/252298-please-help-with-echoing-results/#findComment-1293668 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.