Jump to content

PHP AJAX and MySql Output works, but the output is multiple with same ID


rilana

Recommended Posts

Hi Guyes

 

I didn't do php for a while and now I have to update a project I did a while back. So I dicided to throw some AJAX in there... So I grabed some tutorial and now I am kind of back to scratch. I would really aprechiate your help.

 

I have a database, a html and a php file.

Rightnow things looke like this: http://neu.smartpersonal.ch/stellen.php

 

At first looke it seems to work, but then I realized that it puts jobs with the same ID out more then once. Much more then once...

 

My HTML looks like that:

 
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","stellenResult.php?q="+str,true);
xmlhttp.send();
}
</script>


</head>
<body id="stellen">
<div id="container">
<div id="banner" ><h1> </h1>		
  </div>

<div id="left">

	<a href="index.php"><img src="pic/logoLeftWeb.gif" border="0" />	</a></div>
<div id="right">


</div> <!-- end menu right -->
<div id="content">
    <div id="nav"><? include("nav.html"); ?>
</div>
    <h3><strong>Finden</strong> Sie Ihre <strong>Gelegenheit</strong></h3>
    
    <form>
<select name="users" onchange="showUser(this.value)">
<option value="">Kagegorie wählen:</option>
<option value="1" />Technische Berufe</option>
<option value="3" />Bau</option>
<option value="4" />Verkauf</option>
<option value="2" />Kaufmännische Berufe</option>
</select>
</form>

<div id="txtHint"><b>Person info will be listed here.</b></div>

 

And my PHP looks like that:

<?

//java
$q=$_GET["q"]; 


// Make a MySQL Connection
$con = mysql_connect("", "", "") or die(mysql_error());

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("", $con);
  
  
mysql_query("SET NAMES 'UTF8'");  




$sql = "SELECT
		*
	FROM 
		stelle 
	JOIN 
		stelle_region
	ON
		stelle_region.stelleID=stelle.stelleID
	JOIN
		region
	ON
		region.regionID=stelle_region.regionID
	JOIN 
		stelle_beruf
	ON
		stelle_beruf.stelleID=stelle.stelleID
	JOIN
		beruf
	ON
		beruf.berufID=stelle_beruf.berufID

	WHERE stelle_beruf.berufID = '".$q."'";

echo $sql;



$result = mysql_query($sql);


$r = mysql_fetch_row($result);  
$numrows = $r[0];  
$numrows = mysql_num_rows ($result);




//print table
echo "<table width='100%' border='0' cellpadding='0'>";
echo "<tr height='40px'><td>";
echo "Ihre Suche ergab $numrows Treffer";
echo "</tr></td><td></td></tr>";


while($row = mysql_fetch_array( $result )) {

$id=($row['stelleID']);
$datumsanzeige=($row['stelleDatumsanzeige']);
$datum=(date("d.m.y", strtotime($row["stelleDatum"])));
$today = date("d.m.y");

if($datumsanzeige == "fake")
    {
    $datumDef = "$today";
    }
  else
    {
    $datumDef = "$datum";
    }


// Print out the contents of each row into a table
echo "<tr><td class='stellen'>"; 
echo $row['stellePosition'];
echo "<br>";
echo $row['berufName'];
echo "<br>";
echo $row['stelleID'];
echo "</td><td>"; 
echo "$datumDef";
echo "</td></tr><tr><td>"; 
//take <li> away
$text=strip_tags ($row['stelleStellenbeschrieb']);
// 0,100 show 100 Zeichen
echo substr($text,0,100);
echo "... ";
echo "<a href=\"stellenDetail.php?stelleID=$row[stelleID]\">|weiter > </a>";
echo "</td></tr>"; 
echo "<tr><td>";
echo "</td></tr>";
echo "<tr><td colspan='2' class='line'><br></td><td></td></tr>"; 

} 
echo "<tr><td>";



echo "</td></tr>";
echo "</table>";



echo mysql_error();
mysql_close($con);

?> 

 

I dont understand why it would put the same id's out more then once...??? And I dont see a pattern in it eighter. I would really aprechiate some help or hints thank you so much!

 

Rilana

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.