Page 1 of 2

i need to ask

Posted: Sat Feb 01, 2003 1:45 pm
by forgun
here in that code

Code: Select all

<?php
$qur = "select id , title from News where 1 order by id desc limit 0, 4";
$res = mysql_query($qur) or die (mysql_error());
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
	$id = $row["id"];
	$tit = $row["title"];
}
?>
i try to change to swtich and none help he give me the data only for the first id
so how i can do at the i can view the data on the last 4 entered data

Posted: Sat Feb 01, 2003 2:30 pm
by McGruff
I'm fairly new to all this, but I think your query string is missing something:

select id , title from News where 1 order by id desc limit 0, 4

should I think be:

select id , title from News where column_name='1' order by id desc limit 0, 4

See mysql.com for the mysql manual.

Posted: Sat Feb 01, 2003 2:39 pm
by forgun
i thing not because i dont know from what id is the last on the db table
so where 1 i dont know what is doing there i really whant to know
but some one tell me to puit that there

Posted: Sat Feb 01, 2003 2:49 pm
by McGruff
You can get the maximum value for a column with

SELECT MAX(column_name) AS column_name FROM table_name

READ THE MANUAL :roll:

Posted: Sat Feb 01, 2003 2:52 pm
by mydimension
that "where 1" part isn't neccessary

are you doing anything else insode that while loop? or is this the entire code? in order to use each record in the table your code must reside within the while loop.

Posted: Sat Feb 01, 2003 2:56 pm
by forgun
what are u mean can u plz show methis is almost the entire code
what i need to do that what the php manual is say to do for get the data so that what i done there is anuder way?

Posted: Sat Feb 01, 2003 3:05 pm
by mydimension
my guess is that your code looks something like this:

Code: Select all

<?php
$qur = "select id , title from News where 1 order by id desc limit 0, 4";
$res = mysql_query($qur) or die (mysql_error());
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
   $id = $row["id"];
   $tit = $row["title"];
}
print $id;
print $tit;
?>
those two print lines need to be located inside the while loop or else they are only going to print one recorde of your data. this is what it should look like:

Code: Select all

<?php
$qur = "select id , title from News where 1 order by id desc limit 0, 4";
$res = mysql_query($qur) or die (mysql_error());
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
   $id = $row["id"];
   $tit = $row["title"];
   print $id;
   print $tit;
}
?>

Posted: Sat Feb 01, 2003 3:16 pm
by forgun
u miss understood me
the prob is
for exp id = 45 is the last info get in
i try to get info form
the id's
45,44,43 and 42
the prob is only 45 is been view so how i can kill this prob

Posted: Sat Feb 01, 2003 4:32 pm
by mydimension
it might be easier to debug this if you show the entire code that you are using.

Posted: Sun Feb 02, 2003 12:12 am
by forgun
what i give to u is all the code there is some i didnt show that are like that <?= $
like print so

Posted: Sun Feb 02, 2003 7:02 am
by mydimension
well, show that too. everything that is in that file. it is all part of the same script and is therefore all related. everything that is in that file you should paste into here so we can see what is going on.

Posted: Sun Feb 02, 2003 2:31 pm
by forgun

Code: Select all

<?PHP
include("includes/dbs.php");
@$lk = mysql_connect($serv,$user,$pass) or die (mysql_error());
$db = mysql_select_db($dbname,$lk);
$qur = "select id , title from News where 1 order by id desc limit 0, 4";
$res = mysql_query($qur) or die (mysql_error());
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) &#123;
	$id = $row&#1111;"id"];
	$tit = $row&#1111;"title"];
&#125;
?>
<html dir="rtl">

<head>
<meta http-equiv="Content-Language" content="he" />
<meta name="GENERATOR" content="Microsoft FrontPage 5.0" />
<meta name="ProgId" content="FrontPage.Editor.Document" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255" />
<title>úôøéè á÷øä</title>
</head>

<body bgcolor="#C0C0C0" link="#00FFFF" vlink="#00FFFF" alink="#00FFFF">

<p align="center"><u><font size="7" color="#0000FF" face="Aharoni"><b>ùéðåééí
ìòéãëåðéí</b></font></u></p>
<form method="POST" action="upch.php" target="I1">
  <p align="justify"><span lang="he">&nbsp;</span><select size="1" name="D1" style="border: 3px double #800000; background-color: #808000">
<?
	echo "<option value='" .$id . "'>" $tit "</option>\n";
?>
</select></p>
  <p align="right"><input type="submit" value="áçø òéãëåï" name="B1" style="border-style: ridge; border-width: 1" /></p>
</form>
<p align="justify"><iframe name="I1" width="937" height="259" scrolling="no" style="border: 1px dotted #000080" border="0" frameborder="0" src="tst.php">
Your
browser does not support inline frames or is currently configured not to display
inline frames.</iframe></p>
<p align="justify"><input type="button" value="çæåø" name="B1" style="border-style: ridge; border-width: 1" onclick="javascript:history.go(<?= $many?>)"/></p>

</body>

</html>
here

Posted: Sun Feb 02, 2003 2:50 pm
by evilcoder
I've never seen WHERE 1 in my life! what is that supposed to mean? Where 1 what?

and MYSQL_ASSOC whats that?

Another might be to Take out the @ on your database variable. You WANT to see whats going wrong.

Posted: Sun Feb 02, 2003 3:10 pm
by forgun
in some places yes in some no
p.s
MYSQL_ASSOC is on the php manual see there

Posted: Sun Feb 02, 2003 3:16 pm
by hob_goblin
try this:

Code: Select all

<?PHP 
include("includes/dbs.php"); 
@$lk = mysql_connect($serv,$user,$pass) or die (mysql_error()); 
$db = mysql_select_db($dbname,$lk); 
$qur = "select id , title from News order by id desc limit 4"; 
$res = mysql_query($qur) or die (mysql_error()); 
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) &#123; 
   $id&#1111;] = $row&#1111;"id"]; 
   $tit&#1111;] = $row&#1111;"title"]; 
&#125; 
?> 
<html dir="rtl"> 

<head> 
<meta http-equiv="Content-Language" content="he" /> 
<meta name="GENERATOR" content="Microsoft FrontPage 5.0" /> 
<meta name="ProgId" content="FrontPage.Editor.Document" /> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255" /> 
<title>úôøéè á÷øä</title> 
</head> 

<body bgcolor="#C0C0C0" link="#00FFFF" vlink="#00FFFF" alink="#00FFFF"> 

<p align="center"><u><font size="7" color="#0000FF" face="Aharoni"><b>ùéðåééí 
ìòéãëåðéí</b></font></u></p> 
<form method="POST" action="upch.php" target="I1"> 
  <p align="justify"><span lang="he"> </span><select size="1" name="D1" style="border: 3px double #800000; background-color: #808000"> 
<? foreach($id as $key => $val)&#123;
   echo "<option value='" . $val . "'>" . $tit&#1111;$key] . "</option>\n"; 
&#125;
?> 
</select></p> 
  <p align="right"><input type="submit" value="áçø òéãëåï" name="B1" style="border-style: ridge; border-width: 1" /></p> 
</form> 
<p align="justify"><iframe name="I1" width="937" height="259" scrolling="no" style="border: 1px dotted #000080" border="0" frameborder="0" src="tst.php"> 
Your 
browser does not support inline frames or is currently configured not to display 
inline frames.</iframe></p> 
<p align="justify"><input type="button" value="çæåø" name="B1" style="border-style: ridge; border-width: 1" onclick="javascript:history.go(-1)"/></p> 

</body> 

</html>