Jump to content

Retrieving data from the database problem


djbaze

Recommended Posts

Hello Everybody,

I have a problem with my php code, where I'm trying to retrieve some data from a MYSQL Database.

I don't know why it doens't work, I have another script where I use the same trick, and there it works perfect!

Here the code of the not working page:

<?php
/* Here i set the value that will be if you havent set a value jet. */
$airline = ''; 
$aircraft  = '';
/* Here i check if one of the values have been set and then sets the value to what the value have been set too */
if(isset($_GET["airline"])) $airline=$_GET["airline"];
if(isset($_GET["aircraft"])) $aircraft=$_GET["aircraft"];


/* Lets do the queries! */

$db_host = 'localhost';
$db_user = 'xxx';
$db_pwd  = 'xxxx';

$database = 'ricardoaircrash';
$table = 'content';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

$query="SELECT * FROM content WHERE airline='$airline'";
$query2="SELECT * FROM content WHERE aircraft='$aircraft'";
$result=mysql_query($query);
$result2=mysql_query($query2);

if (!airline) {
$num=mysql_numrows($result2); } else {
$num=mysql_numrows($result); }
?>

<?php
$i=0;
while ($i < $num) {

// here I check wherever you searched on a aircraft or airline..
if (!$aircraft){
$f1=mysql_result($result,$i,"airline");
$f2=mysql_result($result,$i,"aircraft");
$f5=mysql_result($result,$i,"crashdate");
$f3=mysql_result($result,$i,"content");
$f4=mysql_result($result,$i,"image");}
else {
$f1=mysql_result($result2,$i,"airline");
$f2=mysql_result($result2,$i,"aircraft");
$f5=mysql_result($result2,$i,"crashdate");
$f3=mysql_result($result2,$i,"content");
$f4=mysql_result($result2,$i,"image");
}



// and then I echo the value's..
?>

<div align="center"><?php echo $f1; ?> <?php echo $f2; ?>  <?php echo $f5; ?><br><?php echo $f3; ?><br><br><?php echo $f4; ?><br></div>
<?php
$i++; }
?>

 

The thing is, when I search on a Airline, the script does his job, but when I search on a Aircraft, nothing happends...

 

Then the code that does work (i'm sorry, this is with some tables, and im sorry, but no comments......):

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!-- saved from url=(0014)about:internet -->
  <title>Aviation & Flight Simulator - History of Aviation</title>


  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

  <style type="text/css">td img {display: block;}</style>
  <link rel="stylesheet" href="style.css" type="text/css" />

  <script type="text/javascript" src="timeFormat.js"></script>
  <script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
if (event == "init" && args.length > 2) {
if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
nbArr[nbArr.length] = img;
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = args[i+1];
nbArr[nbArr.length] = img;
} }
} else if (event == "over") {
document.MM_nbOver = nbArr = new Array();
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
nbArr[nbArr.length] = img;
}
} else if (event == "out" ) {
for (i=0; i < document.MM_nbOver.length; i++) {
img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
} else if (event == "down") {
nbArr = document[grpName];
if (nbArr)
for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
document[grpName] = nbArr = new Array();
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
nbArr[nbArr.length] = img;
} }
}
//-->
  </script>  <link rel="stylesheet" type="text/css" href="chrometheme/chromestyle.css" />

<script type="text/javascript" src="chromejs/chrome.js"></script>

</head>



<body onload="show_clock();MM_preloadImages('images/Home-Clicked.jpg','images/Home-Rollover.jpg','images/HistoryofFS-Clicked.jpg','images/HistoryofFS-Rollover.jpg','images/HisAV-Original.jpg','images/HisAV-Rollover.jpg','images/Planes-Clicked.jpg','images/Planes-Rollover.jpg')" style="background-color: rgb(255, 255, 255);">

<div align="center">
<div style="width:800px">
<div style="text-align: center;"><div class="chromestyle" id="chromemenu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#" rel="dropmenu1">History of FS</a></li>
<li><a href="#" rel="dropmenu2">History of Aviation</a></li>
<li><a href="#" rel="dropmenu3">Planes</a></li>	
</ul>
</div>

<!--1st drop down menu -->                                                   
<div id="dropmenu1" class="dropmenudiv">
<a href="hisfs/history.htm">History</a>
<a href="hisfs/difver.htm">Different Version</a>
<a href="hisfs/img.htm">Image Gallery</a>
</div>


<!--2nd drop down menu -->                                                
<div id="dropmenu2" class="dropmenudiv" style="width: 150px;">
<a href="hisav/wb.htm">Wright Brothers</a>
<a href="hisav/klm.htm">KLM</a>
<a href="hisav/fokker.htm">Fokker</a>
</div>

<!--3rd drop down menu -->                                                   
<div id="dropmenu3" class="dropmenudiv" style="width: 150px;">
<a href="plns/boeing.htm">Boeing</a>
<a href="plns/airbus.htm">Airbus</a>
<a href="plns/img.htm">Image Gallery</a>
</div></div>


<script type="text/javascript">

cssdropdown.startchrome("chromemenu")

</script></div>

<table align="center" border="0" cellpadding="0" cellspacing="0" width="800">

<!-- fwtable fwsrc="Slicesuiteindelijk.png" fwpage="Page 1" fwbase="Slicesuiteindelijk.jpg" fwstyle="Dreamweaver" fwdocid = "1933032323" fwnested="0" -->
  <tbody>

    <tr>

      <td><img src="images/spacer.gif" alt="" border="0" height="1" width="40" /></td>

      <td><img src="images/spacer.gif" alt="" border="0" height="1" width="720" /></td>

      <td><img src="images/spacer.gif" alt="" border="0" height="1" width="40" /></td>

      <td><img src="images/spacer.gif" alt="" border="0" height="1" width="1" /></td>

    </tr>

    <tr>

      <td rowspan="7" background="images/Overflowleft.jpg" id="Overflowleft" alt="" border="0" height="600" width="40" /></td>

      <td colspan="2"><img name="Slicesuiteindelijk_r1_c2" src="images/Slicesuiteindelijk_r1_c2.jpg" id="Slicesuiteindelijk_r1_c2" alt="" border="0" height="1" width="760" /></td>

      <td><img src="images/spacer.gif" alt="" border="0" height="1" width="1" /></td>

    </tr>

    <tr>

      <td border="0" id="Header" alt="" background="images/Header.jpg" height="160" width="720">
      </td>

      <td rowspan="6" background="images/Overflowright.jpg" id="Overflowright" alt="" border="0" height="599" width="40" /></td>

      <td><img src="images/spacer.gif" alt="" border="0" height="160" width="1" /></td>

    </tr>

    <tr>
<div align="center"></div>
      <td border="0" id="Navbar" alt="" background="images/Navbar.jpg" height="42" width="720">
      	</div>
      </td>

      <td><img src="images/spacer.gif" alt="" border="0" height="42" width="1" /></td>

    </tr>

    <tr>

      <td border="0" id="TimeandText" alt="" background="images/TimeandText.jpg" height="25" width="720">
      <script language="javascript" src="liveclock.js">
<marquee direction="left" loop="50" width="65%">Welcome
on the Aviation & Flight Simulator Site</marquee>
      </script></td>

      <td><img src="images/spacer.gif" alt="" border="0" height="25" width="1" /></td>

    </tr>

    <tr>

      <td rowspan="2" border="0" id="Text" alt="" background="images/Text.jpg" height="349" width="720" valign="top">
<?php
/* Here i set the value that will be if you havnt clicked a on a link. */
$brand = ''; 
$type  = '';
/* Here i tjek if one of the links have been clicked and then sets the value to what the link have been set too */
if(isset($_GET["brand"])) $brand=$_GET["brand"];
if(isset($_GET["type"])) $type=$_GET["type"];


/* Lets do the queries! */

$db_host = 'localhost';
$db_user = 'xxx';
$db_pwd  = 'xxxxx';

$database = 'cms';
$table = 'content';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

$query="SELECT * FROM content WHERE titel='$brand'";
$query2="SELECT * FROM content WHERE type='$type'";
$query3="SELECT * FROM content WHERE titel='$brand' AND type='$type'";
$result=mysql_query($query);
$result2=mysql_query($query2);
$result3=mysql_query($query3);
$num=mysql_numrows($result);
$num2=mysql_numrows($result2);
$num3=mysql_numrows($result3);
?>

<?php
$i=0;
while ($i < $num) {



if (!$type){
$f1=mysql_result($result,$i,"titel");
$f2=mysql_result($result,$i,"type");
$f3=mysql_result($result,$i,"content");
$f4=mysql_result($result,$i,"image");}
else {
$f1=mysql_result($result3,$i,"titel");
$f2=mysql_result($result3,$i,"type");
$f3=mysql_result($result3,$i,"content");
$f4=mysql_result($result3,$i,"image");
}




?>

<div align="center"><?php echo $f1; ?> <?php echo $f2; ?><br><?php echo $f3; ?><br><br><?php echo $f4; ?><br></div>
<?php
$i++;
}
?>
<div align="center">
<FORM METHOD="LINK" ACTION="planes.htm">
<INPUT TYPE="submit" VALUE="Back to the planes page!">
</FORM></div>
      </td>

      <td><img src="images/spacer.gif" alt="" border="0" height="348" width="1" /></td>

    </tr>

    <tr>

      <td><img src="images/spacer.gif" alt="" border="0" height="1" width="1" /></td>

    </tr>

    <tr>

      <td><img name="Slicesuiteindelijk_r7_c2" src="images/Slicesuiteindelijk_r7_c2.jpg" id="Slicesuiteindelijk_r7_c2" alt="" border="0" height="23" width="720" /></td>

      <td><img src="images/spacer.gif" alt="" border="0" height="23" width="1" /></td>

    </tr>

  </tbody>
</table>

</div>

</body>
</html>

 

 

Can you guys figure this out for me? I'm stuck, I spend the whole day and night on it... :wtf:

Sometimes I think..  :rtfm:

 

DJ Baze

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.