i need to ask

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

i need to ask

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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:
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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.
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post 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?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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;
}
?>
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post 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
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

it might be easier to debug this if you show the entire code that you are using.
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post by forgun »

what i give to u is all the code there is some i didnt show that are like that <?= $
like print so
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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.
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post 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
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post 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.
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post by forgun »

in some places yes in some no
p.s
MYSQL_ASSOC is on the php manual see there
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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>
Post Reply