Page 1 of 1
new to php
Posted: Wed Jun 01, 2005 5:00 am
by cr-isp
hi again guys,
another silly newbie question
i want to select the table date from one of my databases, and am not exactly sure how to work it. i was going to adapt this query to do it.
Code: Select all
<?php
mysql_connect("localhost","database","password");
$query1 = "SELECT * FROM table WHERE username='$login' and password='$password'";
$result1 = mysql_db_query(database,$query1);
while($row = mysql_fetch_object($result1))
;
}
?>
and was going to display it like this, would this be right
Code: Select all
<?php
mysql_connect("localhost","database","password");
$query1 = "SELECT date FROM maintenance";
$result1 = mysql_db_query(radius,$query1);
while($row = mysql_fetch_object($result1))
;
}
?>
would this work, or can some one tell me the best way to do it
here is my database structure
database is called radius, the tables in there i need is manitenance and the field i need from there is called date.
be great if some one could help
o and there are no special perameters, i just want it to be dispalyed all the time whether ure logged in or not.
Posted: Wed Jun 01, 2005 5:15 am
by anjanesh
You want to know the date of creation of the table or get the values of a date field in the table ?
Posted: Wed Jun 01, 2005 5:20 am
by cr-isp
i have inserted a few dates in the date field and just want to retreive them
basically i have a planned maintenace section, i have an admin back which i can update the date of the next planned maintenance. all i want to do is echo out this date from the date field in the database.
do you follow what im trying to do
Alan
Posted: Wed Jun 01, 2005 5:38 am
by JayBird
Code: Select all
mysql_connect("localhost","database","password");
$query1 = "SELECT date FROM maintenance";
$result1 = mysql_db_query(database,$query1);
$row = mysql_fetch_object($result1);
echo $row->date;
Posted: Wed Jun 01, 2005 6:00 am
by cr-isp
that actually does not work, not sure of the select bit
Alan
Posted: Wed Jun 01, 2005 6:03 am
by JayBird
whoops, this should do it
Code: Select all
mysql_connect("localhost","database","password");
$query1 = "SELECT date FROM maintenance";
$result1 = mysql_query($query1) or die(mysql_error());
$row = mysql_fetch_object($result1);
echo $row->date;
Posted: Wed Jun 01, 2005 7:13 am
by cr-isp
right then, yeah that seems to be working, which is great the only thing i seem of not mastered yet is updating and deleting.
can any one cast there eye over what has been posted and point me in the rihgt direction as how to update and delete the following.
i need to update,
date
start
finish
there field names
and there stored in maintenance table which is inn radius database
would i be rihg in thinking it would go something like this
Code: Select all
$query = "UPDATE maintenance SET date = '$date, start = '$start, finish = '$finish' ";
i know the form fields will act as $date etc just wondering where to post it to, do i post it to the page where the results wil be displayed.
and will the full query look like this
Code: Select all
<?
mysql_connect("localhost","radius","2u8GvsCy");
$query1 = "UPDATE maintenance SET date = '$date, start = '$start, finish = '$finish'";
$result1 = mysql_db_query(radius,$query1);
while($row = mysql_fetch_object($result1));
?>
not sure the fetch line should be in there, can any one help
Alan
Posted: Wed Jun 01, 2005 8:33 am
by Chris Corbyn
No need for the mysql_fetch_object().
Also, what you just posted would cause major problems cos you dont have a WHERE clause in there (it will update ALL records with the same data without it).
You should have some sort of a primary key in your database. Use that in the WHERE clause.
Code: Select all
$query = "UPDATE maintenance SET date='$date', start='$start', finish='$finish' WHERE id='$id'";
Posted: Wed Jun 01, 2005 9:21 am
by cr-isp
thanks for your reply, been looking at the ID part of things and i understand why its needed, i just can figure out where its pulled from.
for instance i am trying some code i found on this forum and trying to adapt it to my needs, it does state about the ID field, which i do have in the database, there will only ever be one ID in there which in the number 1.
can i just hard set the number one as the ID, if not where does the script get the ID from as i dont seem to be inputting it any where, and i cant seem to find where the script sources it from.
heres the code i am trying to use
Code: Select all
<?php
// connection details here
mysql_connect("localhost","radius","password");
$query1 = "SELECT * FROM manintenance WHERE id='$id'";
$result1 = mysql_db_query(radius,$query1);
while($row = mysql_fetch_array($result1)) {
echo("
<body>
<form name=maintenance method=post action=edit_manintenance.php>
<div align=left>
<table width=302 border=0 cellpadding=4 cellspacing=1 bgcolor=#FFFFFF>
<td width=12% align=right><div align=left><font face=Verdana style=font-size:8pt>Date:</font></div></td>
<td width=79%>
<p align=left><font size=1 face=Verdana><span style=font-size: 8pt 8pt>
<input name=date type=text size=25 value=".$row->date."</span></font></td>
</tr>
<td align=right><div align=left><font face=Verdana style=font-size:8pt>Start:</font></div></td>
<td>
<p align=left><font size=1 face=Verdana><span style=font-size: 8pt 8pt>
<input name=start type=text size=20 value=".$row->start."</span></font></td>
</tr>
<td align=right><div align=left><font face=Verdana style=font-size:8pt>Finish:</font></div></td>
<td>
<p align=left><font size=1 face=Verdana><span style=font-size: 8pt 8pt>
<input name=finish type=text size=20 value=".$row->finish."</span></font></td>
</tr>
<td><div align=right><input name=id type=hidden value=".$row->id."><input type=submit name=Submit value=Submit></div></td>
</tr>
</table>
</form>
");
}
?>
no that whats i am trying and getting no joy, i cant for the life of me see where this script is pulling the id from.
can any one help with this
Alan