Getting a specific row in DataBase

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

Post Reply
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Getting a specific row in DataBase

Post by Draco_03 »

Hey :)

mhh i m using access database (odbc)
so to get a row i use
odbc_fetch_row($queryexe)

but if i want to get a specific row (cuz the fetch row get my last row entered.. wich is good for what i ve done.. but now i want to be able to click on the client name and Then show all his info)

PS : i have a primary key that always get incremented (automaticaly) so i could like ask to display the row of the key i m asking.. but i m not sure of the syntaxe..

Code: Select all

$connect = odbc_connect("tech_support", "kader", "edh") or die("Connection failed");
$query = "SELECT key FROM Clients";
$queryexe = odbc_do($connect, $query);
while(odbc_fetch_row($queryexe)) 
    { 
    $varkey = odbc_result($queryexe, 1);
    }
$var = $varkey;
if ($var == "NULL") {
$var == 1;
}else{
$var++;
}
oh i m a noob..so i know it s not optimise :roll:

thx :)
User avatar
wmasterj
Forum Commoner
Posts: 40
Joined: Mon Aug 18, 2003 5:52 pm
Location: Stockholm, Sweden

Post by wmasterj »

first of all, i would edit your post and take away the database login-information to your database...or maybe it's locally on your PC?

odbc_connect("xxxx-xxxxxxx", "xxxxx", "xxx")

the way you select only a specific row is by using the 'WHERE' clause
in your case it would look something like this:

Code: Select all

<?php
$query = "SELECT key FROM Clients WHERE key='$key'";
?>
hope you understand

you can read more about mySQL which uses about the same syntax as access SQL:
http://www.mysql.com -> click 'Documentation'

:D :) 8) :wink:
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Yeah it s locally :)

Thx a lot.. i understand your query.. i ll try it
The only thing is i'm not use to php so, since i already have a query (one select and one insert)
i ll have to place my code at the right place.. i ll prolly close my connection at some point and reconnect..

nyways i'll get on it

thx again :)
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Humm , i m not sure why i get an error...
SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression

i ll show my hole code it might help

Code: Select all

<?php
$connect = odbc_connect("tech_support", "kader", "edh") or die("Connection failed");
$query = "SELECT key FROM Clients";
$queryexe = odbc_do($connect, $query);
while(odbc_fetch_row($queryexe)) 
    { 
    $varkey = odbc_result($queryexe, 1);
	}
$date = $_POST['days']."-".$_POST['months']."-".$_POST['years']; 
$nom = $_POST["nom"]; 
$centre = $_POST["centre"];
$phone = "(".$_POST["indicatif"].")"." ".$_POST["phone1"]."-".$_POST["phone2"];
$person = $_POST["person"];
$serial = $_POST["serial1"]." ".$_POST["serial2"]." ".$_POST["serial3"];
$machine = $_POST["machine"];
$ftp = $_POST["ftp"];
$fta = $_POST["fta"];
$tp = $_POST["tp"];
$key1 = $_POST["key1"];
$key2 = $_POST["key2"];
$key3 = $_POST["key3"];
$garantie = $_POST["garantie"];
$problem = $_POST["problem"];
$var = $varkey;
if ($var == "NULL") {
$var == 1;
}else{
$var++;
}
echo ("<tr align='center' class='textegris'>");
echo ("<td><a href='accueil_fr.php' class='textegris'>$centre</a></td>");
echo ("<td><a href='accueil_fr.php' class='textegris'>$nom</a></td>");
echo ("<td><a href='accueil_fr.php' class='textegris'>$phone</a></td>");
echo ("<td><a href='accueil_fr.php' class='textegris'>$var</a></td>");
echo ("</tr>");
odbc_close($connect);
$connect = odbc_connect("tech_support", "kader", "edh") or die("Connection failed");
$query = "INSERT INTO Clients ( thedate, centre, nom, phone, Derniere, machine, ftp, fta, tp, module1, module2, module3, garantie, probleme, key) VALUES ( '$date', '$centre', '$nom', '$phone', '$person', '$machine', '$ftp', '$fta', '$tp', '$key1', '$key2', '$key3', '$garantie', '$problem', '$var')";
$queryexe = odbc_do($connect, $query);
odbc_close($connect);
?>
that the way i use.. i only show the info of 4 field.. and each one i want to put an href on it so u can access info of ALL field on this peticular client...

(just for testing right now i just put accueil_fr.php as a link wich is nothing..it just says thx..)
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

I'm sorry i forgot to say.. the code i posted WORKS.. i didn t add the select you gave me..

8)
Post Reply