|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Protecting Web Applications from Attack and Misuse by Citrix Systems
|
|
#1
|
|||
|
|||
|
Mysql more than 1 query
I have tried to do more than one query but it always goes wrong. Can any of you tell me how to do query and fetch query in Php that more than one time. It is for general code so no code will be given from me.
The code : <?php include("inc/config.incl.php"); class articleListing extends commonComp{ var $tblName, $dbName, $otherweb, $category, $kategori, $id, $doquery, $doquery2, $perPage, $countRow; function countPages($request){ $constant = $this->countRow/10; $allPageCont = ceil($constant); switch($request){ case "all" : return $allPageCont; case "left" : return $this->countRow % 10; } } function isSetNext(){ if(!isset($_GET["next_page"]) || $_GET["next_page"] == ""){ return false; } } function nextPage(){ if(!$this->isSetNext()){ return 0; } elseif($this->isSetNext()){ if($_GET["next_page"] <= $this->countPages("all") ) { return $_GET["next_page"]; } } elseif($this->isSetNext() ){ if($_GET["next_page"] > $this->countPages("all") ) { return 0; } } elseif($this->isSetNext() ) { if($_GET["next_page"] == $this->countPages("all") ) { return $this->countPages("left"); } } } function pageAlgo(){ if($this->nextPage() < $this->countPages("all") ) { return $this->nextPage * 10; } elseif($this->nextPage() == $this->countPages("all") ) { return $this->countPages("left") + ($this->nextPage() * 10); } } function navNum(){ if($this->countPages("all") >= 2){ echo ' <p><a href="" class="blackMediumLink">Next </a>| '; for($i=1;$i <= $this->countPages("all");$i++){ echo '<a href="http://www.newgen.com" class="blackMediumLink">'.$i.'</a> | '; } echo '</p><p> </p>';} } function querySql(){ $sqlSyntax = "SELECT id, otherweb, url, title, description, date, readtimes "; $sqlSyntax.= "FROM ".$this->tblName." LIMIT ".$this->pageAlgo().", ".$this->perPage." ;"; $sqlsyntax2 = "SELECT COUNT(id) FROM ".$this->tblName." ;"; $this->doquery2 = @mysql_query($sqlsyntax2,$this->connect); $this->doquery = @mysql_query($sqlSyntax,$this->connect); $count = mysql_num_rows($this->doquery2); $this->countRow = $count; if(!$this->doquery || !$this->doquery2){ echo "Sorry Server is in Error <p>";echo mysql_error(); exit; } } function processTime(){ $theTime = date('d F Y','$this->date'); return $theTime; } function processRT($chrono){ if($chrono < 1 || $chrono == 1){ return "time";} elseif($chrono >1){ return "times";} } function otherSite(){ if($this->otherweb=="yes"){ return true; } elseif($this->otherweb=="no"){ return false; } } function processId($any){ return $any.$this->id; } function publish(){ while($fetch=@mysql_fetch_array($this->doquery)) { $this->id = $fetch["id"]; $url = $fetch["url"]; $this->otherweb = $fetch["otherweb"]; $title = $fetch["title"]; $description = $fetch["description"]; $date = $fetch["date"]; $readtimes = $fetch["readtimes"]; if($this->otherSite()){ echo '<table width="472" border="0" cellspacing="0" cellpadding="0" height="88"> <tr> <td valign="top" height="26"> <a class="headBlue" href="'.$url.'"> ::'.$this->kategori.':: '.$title.' </a></td> </tr><tr> <td valign="top" height="48"> <span class="blackMedium"> '.$description.' </span></td></tr> <tr> <td valign="top" width="161" class="headBlueSmallU"> <a href="'.$url.'" class="headlink"> '.$url.'</a></td> </tr></table><p> '; } elseif(!$this->otherSite()){ echo '<table width="472" border="0" cellspacing="0" cellpadding="0" height="93"> <tr> <td valign="top" height="26" colspan="2"><span class="headBlue"> <a href="'.$this->processId('http://newgent/tutorial.php?id=').'" class="headBlue">::'.$this->kategori.':: '.$title.' </a></span></td> <td valign="top" height="26" width="146" class="blackmedium"> '.$this->processTime().'</td> </tr> <tr> <td valign="top" height="48" colspan="3"><span class="blackMedium"> '.$description.' </span></td> </tr><tr> <td valign="top" width="165" class="blackMediumLink"> <a href="'.$this->processId('http://newgent/print.php?id=').'" class="blackMediumLink"> Printable version</a></td> <td valign="top" width="161" class="blackMediumLink"> <a href="'.$this->processId('http://newgent/tutorial.php?id=').'" class="blackMediumLink"> Web</td> <td valign="top" width="146" class="blackMedium"> Read : '.$readtimes.' '.$this->processRT($readtimes).'</td></tr> </table><p>'; } } $this->navNum(); @mysql_free_result($this->doquery); @mysql_free_result($this->doquery2); @mysql_close($this->connect); } //constructor function articleListing($enTbl,$inaTbl,$per,$category){ $this->perPage = $per; $this->kategori = $this->produce($category); $this->tblName= $enTbl; echo $this->countRow ; if(isset($_GET["lang"]) && $this->rgpc('get','lang') == 'ina'){ $this->tblName = $inaTbl; } $this->connectionDb(); $this->querySql(); $this->publish(); } } Only having problem in the highlight one !!! Last edited by newgent : August 18th, 2002 at 07:59 AM. |
|
#2
|
|||
|
|||
|
could you please post the code you are using?
and please read the rules, as it will save you a lot of time. Thanks |
|
#3
|
|||
|
|||
|
if you want to have multiple database queries, you need something like this
mysql_connect($dbServ, $dbName, $dbPass); mysql_select_db($dbData); $query1 = mysql_query("SELECT * FROM table"); while($row1 = mysql_fetch_array") { } $query2 = mysql_query("SELECT * FROM table"); while($row2 = mysql_fetch_array") { } |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Mysql more than 1 query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|