Database Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesDatabase Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 26th, 2009, 01:30 PM
Helmer Helmer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 14 Helmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 7 m 59 sec
Reputation Power: 0
Viewing last inserted data from mysql

Hi..

I am trying to make an insert command which after the insert gets the data and the created id from the database and lets the user print out a copy of the inserted data..

The trouble is with my select query, i am searching the database for all emails that matches the one entered into the database, and i am trying to only get the last one, by sorting them ..

But i wont work, can you please help me figure out what is wrong ?

Code:

<?
include("dbinfo.inc.php");
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); 

$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$e  mail','$web','$case')";
mysql_query($query);

mysql_close();


?>
<?
include("dbinfo.inc.php");
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM contacts WHERE email='$email' LIMIT 0, 10 ORDER BY ID ASC";
$result=mysql_query($query);

$num=mysql_numrows($result); 

mysql_close();


?>
<?
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");	
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web"); 
$case=mysql_result($result,$i,"case"); 
?>
<table border="0" cellspacing="5" cellpadding="3" width="50%">
<tr> 
<td BGCOLOR="#CCCC99"><font face="Arial, Helvetica, sans-serif">SUPPORT CASE ID: </font><font face="Arial, Helvetica, sans-serif"><? echo "$id"; ?></font></td>
</tr>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$id"; ?> Name</font></td><td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td>
</tr>
<tr>
<td><font face="Arial, Helvetica, sans-serif">Phone</font></td><td><font face="Arial, Helvetica, sans-serif"><? echo "$phone"; ?></font></td> 
</tr>
<tr> 
<td><font face="Arial, Helvetica, sans-serif">Mobile</font></td><td><font face="Arial, Helvetica, sans-serif"><? echo "$mobile"; ?></font></td>
</tr>
<tr>
<td><font face="Arial, Helvetica, sans-serif">Fax</font></td><td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"; ?></font></td> 
</tr>

<tr><td><font face="Arial, Helvetica, sans-serif">E-mail</font></td><td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>"><? echo "$email"; ?></a></font></td> 
</tr>

<tr><td><font face="Arial, Helvetica, sans-serif">Website</font></td><td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>"><? echo "$web"; ?></a></font></td> 
</tr>

<tr> <td>&nbsp;
</td><td>&nbsp;
</td>
</tr>
<tr> <td>Din Case:
</td><td>
</td>
</tr>
</table>

<table border="0" BORDERCOLOR=black cellspacing="5" cellpadding="3" width="75%">
<tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$case"; ?></font></td>
<?
++$i;
} 
echo "</table>";


?>

Reply With Quote
  #2  
Old May 27th, 2009, 09:42 AM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 408 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 20 h 27 m 28 sec
Reputation Power: 2
I don't know much about mysql, however I can give you the basic sql for what you want.

SELECT Max(ID) FROM contacts WHERE email='$email'

Have fun!
__________________
P.S. I am looking for work. <grin>.

Reply With Quote
  #3  
Old June 17th, 2009, 04:58 AM
kusuma.yella kusuma.yella is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 5 kusuma.yella User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 13 m 50 sec
Reputation Power: 0
Post Last Inserted value

As per my understanding,u r trying to get the last inserted value from a table as I didn't get exactly the problem.Any way have a look.

It will work as MAX() works.
Try this with ur MySQL CommandLine Client,Create table with auto increment column and some other columns if u want.Then through comandline client insert records into that table by issuing command like
mysql> insert into last(name,sal)values('xxxxx',10000);
It will automatically insert value for auto increment column ,say Id.Then immediately use
mysql> select LAST_INSERT_ID(); to get the last value inserted into the table last.
mysql>select distinct(last_insert_id()) from table_name where email='email_column_value';

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesDatabase Development > Viewing last inserted data from mysql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
Stay green...Green IT