When i first do a search I want the results to have unique ID. However they are just listed in order 0, 1, 2, 3.
How do I fix this? Also get rid of the �?
http://agecon2.tamu.edu/people/faculty/ ... ?page=view
Why is my primary code not working?
Moderator: General Moderators
-
peachiness
- Forum Commoner
- Posts: 41
- Joined: Mon Oct 11, 2010 1:33 pm
- DigitalMind
- Forum Contributor
- Posts: 152
- Joined: Mon Sep 27, 2010 2:27 am
- Location: Ukraine, Kharkov
Re: Why is my primary code not working?
Show your code
-
peachiness
- Forum Commoner
- Posts: 41
- Joined: Mon Oct 11, 2010 1:33 pm
Re: Why is my primary code not working?
Code: Select all
<div id="letsSearch"><br><Br>
Search:
<br>
<input type="text" id="search1" name="search1" onkeypress="keypress(event);" size="40">
<input type="button" value="Search" onClick="specSearch()">
<br><br>
Advanced Search:
<br>
<a href="javascript://" onClick="dataSort('Author')">Author</a>
| <a href="javascript://" onClick="dataSort('Keyword')">Keyword</a>
| <a href="javascript://" onClick="dataSort('Date')">Date</a>
| <a href="javascript://" onClick="dataSort('Type')">Type</a>
| <a href="javascript://" onClick="dataSort('Standard Reference')">Standard Reference</a>
<div id="sortBy" id="sortby" style="visibility: hidden;"></div>
</div>
</div> <!-- table-cell --->
</div>
<div id="data" id="data" style="visibility: hidden;">
</div>
<div class="seperate">
</div>
<div class="missInformation">
Click on a title to sort the table.
</div>
<div class="database">
<table class="sortable" cellspacing="0" id="dataTable">
<tr id="topRow">
<th>ID</th>
<th>Standard Reference</th>
<th>Link</th>
</tr>
<?php
if(@$_GET['action'] == "delete")
{
if($userCheck == "admin"){
$cID = $_GET['cID'];
echo "Deleting Datbase ID " . $cID . "<br />";
mysql_query("DELETE FROM publications where id = '$cID'") or die(mysql_error());
}
else{
require('error.php');
error('666');
}
}
$z = 0;
$result = mysql_db_query("a2288820_data","SELECT * FROM publications ORDER BY id");
while(($row = mysql_fetch_array($result)))
{
echo "<tr>\n";
if(@$userCheck == "admin"){
echo "<td id=\"noLinkTd\"><a href=\"?page=edit&cID=".$row[0]."\">[Edit] ".$z."</a><br />";
echo " <a href=\"javascript://\" onClick=\"deleteRo(".$row[0].",".$z.")\">[Remove]</a>";
echo "</td>\n";
}
else
echo "<td>".$z."</a></td>\n";
echo "<td class='blah'>".$row[35]." </td>\n";
echo "<td><a href=\"".$row[36]."\">".$row[36]."</a> </td>\n";
echo "</tr>\n";
$z++;
}
?>
</table>
</div>
<script type="text/javascript">
function deleteRo(a,b)
{
if(confirm("Are you sure you want to delete row " + b + " ?"))
{
location = "?page=view&action=delete&cID=" + a;
}
}
function keypress(e)
{
var Ucode=e.keyCode? e.keyCode : e.charCode
if (Ucode == 13)
{
specSearch();
}
}
function specSearch(){
x = document.getElementById("search1");
y = x.value;
searchBase(y,'all');
}
var xmlHttp
function dataSort(a)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="functions.php";
url=url+"?sort="+a;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById('sortBy').style.visibility = "visible";
document.getElementById('sortBy').innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
//Showing Data
var xmlHttp2
function searchBase(a,b)
{
xmlHttp2=GetXmlHttpObject2();
if (xmlHttp2==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="functions.php";
url=url+"?search="+a;
url=url+"&by="+b;
xmlHttp2.onreadystatechange=stateChanged2;
xmlHttp2.open("GET",url,true);
xmlHttp2.send(null);
}
function stateChanged2()
{
if (xmlHttp2.readyState==4)
{
document.getElementById('data').style.visibility = "visible";
document.getElementById('data').innerHTML=xmlHttp2.responseText;
}
}
function GetXmlHttpObject2()
{
var xmlHttp2 = null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp2 = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
alert("JDLJF");
try
{
xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp2;
}
</script>
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: Why is my primary code not working?
This line:
needs to be changed, $z simply contains the index of your 'while' loop. You want the id of each article. I cant tell you exactly how to do this, because I don't know the structure of your database table, but I guess that you should replace $z with $row['id'].
Also, remove the link closing tag </a>. You haven't opened a link so you can't close one.
I can't see any strange characters on your page.
I note however that the page source for your webpage contains this
at the top, before the opening doctype declaration. This has clearly been misplaced from somewhere else and may cause problems in some browsers.
Code: Select all
echo "<td>".$z."</a></td>\n";Also, remove the link closing tag </a>. You haven't opened a link so you can't close one.
I can't see any strange characters on your page.
I note however that the page source for your webpage contains this
Code: Select all
<div>
<a href="?page=view" COLOR="#990000" id="body"><b><FONT SIZE=+6>Publications</a></font></B>
<body background="blue_pap(1).jpg">
</div>
-
peachiness
- Forum Commoner
- Posts: 41
- Joined: Mon Oct 11, 2010 1:33 pm
Re: Why is my primary code not working?
cpetercarter: Thanks for the suggestion! I tried it in the code, but nothing seems to have changed ><
Would you have any other recommendations?
Would you have any other recommendations?