hi again need a little help with printing from database i have got it to print with javascipt but need some help on how to print it neater i presume it may be style sheet not sure this is how it prints at the moment 1.... Digoxin .... Morning .... 1 .... 125 micr .... cardiac glycosides (slows heart) 2.... Warfarin .... Evening .... 2 & 1 .... 1mg .... Anticoagulant (blood thiner) 3.... Bumetanide .... Morning .... 2 .... 1mg .... diuretic (water Tablet) 4.... Simvastatin .... Evening .... 1 .... 10mg .... hmg-coa reductase (colestral) 5.... Bisoprolol Fumarate .... Morning .... 1 .... 5mg .... Beta Blocker (blood Pressure) this is the code i use to print would like it in colums so it all lines up cheers Doug
print with javascript? Use a HTML table to format the data as it comes out of the db. something like <table> <tr><td>Field 1<td>Field 2......</tr></table> put it inside the loop for outputting the data. Table tags should be before and after the loop.
Thanks for that will go and look at tables never used them before cheers Doug ok had a look and havnt got a clue if any one can help
It should look something like this ... echo "<table>"; // start loop echo "<tr><td>$i<td>$info['name'] <td>$info['region']<td>$info['username'] <td>$info['password']"; echo "<td>$info['email'] </tr>"; $i++; } //end loop echo "</table>"; quick explanation is: table ->starts the table tr->Table Row td->Cell in a row (think columns)
cant get this to work while($info = mysql_fetch_array( $data )) { //Outputs the image and other data echo "<table>"; // start loop echo "<tr><td>$i<td>$info['name'] <td>$info['region']<td>$info['username'] <td>$info['password']"; echo "<td>$info['email'] </tr>"; $i++; } //end loop echo "</table>"; ?> PHP:
Is it showing anything? Errors? Did you check the source for the page? echo "<table>"; // start loop while($info = mysql_fetch_array( $data )) { //Outputs the image and other data echo "<tr><td>$i<td>$info['name'] <td>$info['region']<td>$info['username'] <td>$info['password']"; echo "<td>$info['email'] </tr>"; $i++; } //end loop echo "</table>"; ?> PHP:
//Retrieves data from MySQL $data = mysql_query("SELECT * FROM shirleys_tablets") or die(mysql_error()); //Puts it into an array $i=01; while($info = mysql_fetch_array( $data )) { PHP:
here is the full code <?php // Connects to your Database $dbh=mysql_connect("l", "c", "s") or die('I cannot connect to database because: ' .mysql_error()) ; mysql_select_db("caravanh_users"); //Retrieves data from MySQL $data = mysql_query("SELECT * FROM shirleys_tablets") or die(mysql_error()); //Puts it into an array $i=01; while($info = mysql_fetch_array( $data )) { //Outputs the image and other data Echo"<table>"; // start loop Echo"<tr><td>$i<td>$info['name'] <td>$info['region'] <td>$info['username'] <td>$info['password'] "; Echo"<td>$info['email'] </tr>"; $i++; } //end loop Echo "</table>"; ?> </p> <p><a href="javascript: window.print();">Print Out</a></p> <p><a href="index.php">Home</a> </p> </body> PHP:
Everythings the same as what you had working before correct? Did you check the HTML page source to see if there was something preventing it from displaying in the browser?
$dbh=mysql_connect("l", "c", "s") or die('I cannot connect to database because: ' .mysql_error()) ; l,c,s ? the first should be localhost, or do you mean for those to be variables?
Well looks like you have to use this screwed up method to make it work: Echo"<tr><td>$i<td>" . $info['name'] . "<td>" . $info['region'] ."<td>" . $info['username'] ."<td>" . $info['password'] ; Echo"<td>". $info['email'] ." </tr>";