php - Looping through every record from database -


i've searched on internet this, , questions here on using else php. ask own question.

what need make button print out (read literally print, in downloading word document details on it) every record database.

the id named 'abstract_id'.

what i'm going show next print button pages, mean if click on said button print specific page:

$abstract_id = addslashes($_post['abstract_id']);     //here connect database//  $query = "select * abstracts abstract_id = '$abstract_id'";     $result = mysql_query($query);      $i = 0;     $title = mysql_result($result,$i,"title");     $author[1] = mysql_result($result,$i,"author1");     $organization[1] = mysql_result($result,$i,"organization1");     $author[2] = mysql_result($result,$i,"author2");     $organization[2] = mysql_result($result,$i,"organization2");     $author[3] = mysql_result($result,$i,"author3");     $organization[3] = mysql_result($result,$i,"organization3");     $author[4] = mysql_result($result,$i,"author4");     $organization[4] = mysql_result($result,$i,"organization4");     $author[5] = mysql_result($result,$i,"author5");     $organization[5] = mysql_result($result,$i,"organization5");     $author[6] = mysql_result($result,$i,"author6");     $organization[6] = mysql_result($result,$i,"organization6");     $format = mysql_result($result,$i,"format");     $language = mysql_result($result,$i,"language");     $presenter = mysql_result($result,$i,"presenter");     $background = mysql_result($result,$i,"background");     $purpose = mysql_result($result,$i,"purpose");     $methods = mysql_result($result,$i,"methods");     $findings = mysql_result($result,$i,"findings");     $conclusion = mysql_result($result,$i,"conclusion");     $word_count = mysql_result($result,$i,"word_count");     $name = mysql_result($result,$i,"name");     $email1 = mysql_result($result,$i,"email1");     $email2 = mysql_result($result,$i,"email2");     $phone1 = mysql_result($result,$i,"phone1");     $phone2 = mysql_result($result,$i,"phone2");     $fax = mysql_result($result,$i,"fax");     $address = mysql_result($result,$i,"address");     $country = mysql_result($result,$i,"country");     $topic = mysql_result($result,$i,"topic");     $master_status = mysql_result($result, $i, "master_status");     $last_edit = mysql_result($result,$i,"last_edit");       header("content-type: application/vnd.ms-word");     header("content-disposition: attachment;filename=abstract_" . $abstract_id . ".doc");      echo "<html>";     echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1252\">";     echo "<body>";     echo "<p><b>pcne abstract</b> $abstract_id</p>";     echo "<h1>$title</h1>";      echo "<b>";     ($i = 1; $i<= 6; $i++) {         echo ((!empty($author[$i-1]) && !empty($author[$i])) ? ", " : "") ;         echo ((!empty($author[$i])) ? $author[$i] . "<sup>" . $i . "</sup>" : "") ;     }     echo ".</b>";      echo "<br>";      ($i = 1; $i<= 6; $i++) {         if (!empty($author[$i])) {             echo (!empty($organization[$i]) && !empty($organization[$i-1])) ? ". " : "";             echo ((!empty($organization[$i])) ? "<sup>" . $i . "</sup>"  . $organization[$i]: "") ;         }     }     echo (!empty($email1)) ? " (" . $email1 . ")" : "";      echo "<br>";     echo "<br>";      echo "<b>background</b>&nbsp;&nbsp;";        echo "$background<br>";       echo "<b>purpose</b>&nbsp;&nbsp;";           echo "$purpose<br>";          echo "<b>method</b>&nbsp;&nbsp;";            echo "$methods<br>";          echo "<b>findings</b>&nbsp;&nbsp;";          echo "$findings<br>";          echo "<b>conclusion</b>&nbsp;&nbsp;";            echo "$conclusion<br>";        echo "</body>";     echo "</html>"; 

now, works fine, need same working button same, instead of printing out 1 record should print all. need foreach or while loop goes through every abstract_id.

it's been ages since last programmed php, appreciate help!

if need clarification, feel free ask.

first don't need 30 lines of mysql_result, use mysql_fetch_assoc values in associative array. have while ( $line = mysql_fetch_assoc($query) ), see above :

header("content-type: application/vnd.ms-word"); header("content-disposition: attachment;filename=abstract_all.doc");  echo "<html>"; echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1252\">"; echo "<body>";  $query = mysql_query("select * abstracts 1") or die(mysql_error()) ; while ( $line = mysql_fetch_assoc($query) ) {     echo "<p><b>pcne abstract</b>".$line['abstract_id']."</p>";     echo "<h1>".$line['title']."</h1>";      $authors = array() ;     ($i = 1 ; $i <= 6 ; $i++ )         if ( isset($line['author'.$i]) && $line['author'.$i] != '' ) $authors[] = $line['author'.$i].' <sup>'.$i.'</sup>' ;     echo '<b>'.implode(', ',$authors).'</b>' ;      $organizations = array() ;     ($i = 1; $i<= 6; $i++)     {         if ( ! isset($line['author'.$i]) || $line['author'.$i] == '' ) continue ; // check if there author, if no go next loop         if ( isset($line['organization'.$i]) && $line['organization'.$i] != '' ) $organizations[] = ' <sup>'.$i.'</sup> '.$line['organization'.$i] ;     }     echo '<b>'.implode(', ',$organizations).'</b>' ;      echo "<b>background</b>&nbsp;&nbsp;";        echo $line['background']."<br>";       echo "<b>purpose</b>&nbsp;&nbsp;";           echo $line['purpose']."<br>";              // ... }  echo "</body>"; echo "</html>"; 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -