Jump to content
php.lv forumi

Datu izvilkšana!


Snaip3Rs

Recommended Posts

Kā var izvilkt datus no db lai piemēram ieeju profilā un tur rāda cilvēka datus pēc ID

<?php
$con = mysql_connect("localhost","admin","jz");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("db", $con);

$result = mysql_query("SELECT * FROM members");

while($row = mysql_fetch_array($result))
 {
 echo $row['username'] . " " . $row['ptz'];
 echo "<br />";
 }

mysql_close($con);
?> 

Piemēram username izvilkt no db. Kā to var izdarīt tas ir tik vienkārš jautājums bet man nesanāk! :(

Link to comment
Share on other sites

Tev kaut kādā veidā ir jāiegūst profila ID, kuru vēlies apskatīt.

 

<?php
$con = mysql_connect("localhost","admin","jz");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("db", $con);
$id = intval($_GET['id']);
$result = mysql_query("SELECT * FROM members WHERE id = '".$id."' LIMIT 1");
$row = mysql_fetch_array($result);

print_r($row);

mysql_close($con);
?> 

 

Tālāk pats skaties ko vari attēlot un to arī attēlo

Link to comment
Share on other sites

Paldies sanāca, bet kā man uztaisīt lai attēlo tikai username email ptz

Lūkur kods!

 <?php
   if($profile_details != NULL) {     
     // use $profile_details to output the users details that
     // we fetched from out database earlier, I'm just going
     // to output all the user info to prove it works
     foreach($profile_details as $k => $v) {
       echo $k . " = " . $v . "<br />";
     }
   } else {
     // display our error message
     echo $error_feedback;
   }
 ?>

$k = $v

izvada pat paoli un parāda visiem pārējiem.

Kā to novērst?

Link to comment
Share on other sites

<?php
$con = mysql_connect("localhost","admin","jz");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("db", $con);
$id = intval($_GET['id']);
$result = mysql_query("SELECT * FROM members WHERE id = '".$id."' LIMIT 1");
$row = mysql_fetch_array($result);

echo $row['username'].'<br />'.$row['email'].'<br />'.$row['ptz'];

mysql_close($con);
?> 

Link to comment
Share on other sites

Šajā lapā man izdevās izvadīt lietotājvārdu un visu pārējo, bet sākumlapā nesanāk!

Te būs kods:

<?
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>

<INPUT TYPE="BUTTON" VALUE="Iziet" ONCLICK="window.location.href='logout.php'">

<INPUT TYPE="BUTTON" VALUE="Lietotaji" ONCLICK="window.location.href='members.php'">


 <?php
$con = mysql_connect("localhost","admin","jz");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("db", $con);
$id = intval($_GET['id']);
$result = mysql_query("SELECT * FROM members WHERE id = '".$id."' LIMIT 1");
$row = mysql_fetch_array($result);
mysql_close($con);
?>

Hello: <?php echo $row['username']; ?>

Link to comment
Share on other sites

Briedi tā ir tā lieta ka error nemet ārā parasts text uzrādās bet no db nevelk ārā username!

Un ja es taisu ar cokie tad man nav jāpārtaisa register un login lapa?

 

nu a tu pirms kvērija izvadī, vai Id kaut ko satur, un paskaties vai datubāzē toč ir ar tādu id.

VAJAG DEBUGGOT!!!!

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa

 

 

fak, ja kas te saskartos ar problemu vispirms visam kodam izbrauktu cauri, dažādās vietās pārbaudītu mainīgo vērtības, ieslēgtu kļūdu paziņojumus, tad te būtu uz pusi mazāk muļķīgu jautājumu...

 

Dziļa ieelpa 1..2..3..4.. briedis ir nomierinājies.

Edited by briedis
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...