Jump to content

[SOLVED] Resource id#4


refiking

Recommended Posts

read this please

<?php //use ?php format as it defualt in php.ini and safe opening for php programming.

//database connection

//database correct connection format, even theo there other ways......

$db=mysql_connect("localhost or ip or url","name of user","password for user");
$db_result=mysql_select_db("database using",$db);

// selecting a standard database query of all entrys.

$sql1="SELECT * FROM whatever";
$sql_result1=mysql($sql1);
while(list($key,$val)=mysql_fetch_assoc($sql_result1))){
echo "$key <br> $val";
}
//The above will list all entry's via $key $val useing the while loop and list function....

// selecting a name via it were clause and other info as needed....

$sql2="SELECT * FROM whatever where name='petter'";
$sql_result2=mysql($sql2);
while($row=mysql_fetch_assoc($sql_result2)){
echo " ".$row['name']."  <br> ".$row['id']." ";
}

// The above will echo out the name off petter and only petteres info as stated in the were //clause and any other record needed via the while loop of petter only and it field name $row[''] //asked, example the $row id was added of petters only.....


// selecting only id and name via where name='petter'

$sql3="SELECT name,id FROM whatever where name='petter'";
$sql3_result=mysql($sql3);
while($row=mysql_fetch_assoc($sql_result3))){
echo " ".$row['name']."  <br> ".$row['id']." ";
}

// same as last above example, except we can only see the id and name as it been seleted via //the select query and it in relation with the name petter only set via the were clause........


// selecting only name via where name='petter and using no while loop ...

$sql4="SELECT name FROM whatever where name='petter'";
$sql4_result=mysql($sql4);
$row=mysql_fetch_assoc($sql_result4));
echo " ".$row['name']." ";


// same as last above example, except we can only see the id and name as it been seleted via //the select query and it in relation with the name petter only set via the were clause........
// but also were only getting one result of a name so we dont need a while loop, but if we //wanted to also see the id of petter we should use the while loop........


//WARNING old programming before sessions.

//this is bad programming but it still happends belevle it or not, let say we wanted to select //petter info via his id but we have no session set and dont no petters id.......


// first we get petters id via one select statement and no while loop........

sql5="SELECT id FROM whatever where name='petter'";
$sql5_result=mysql($sql5);
$row1=mysql_fetch_assoc($sql_result5));

//Another select statement to get petters info via the above id select statement...

sql6="SELECT * FROM whatever where name='petter' and user_id=' ".$row1['id']." ' ";
$sql6_result=mysql($sql6);
while($row2=mysql_fetch_assoc($sql_result6));
echo"  ".$row2['user_id']." <br> ".$row2['name']." <br> ".$row2['age']." ";
}

// the above selects the first select statement to get the users id then the secound echo the info............

// what ever way you select users info all you need to do is use any other mysql function like //DELETE,UPDATE in the while loop to do anythink elese you need to do........
//if you got the users id in a session just use that session in a where clause..

my littele tutoral good luck 
?>

 

example for u.

<?php
$sql4="SELECT id FROM whatever where name='petter'";
$sql_result4=mysql($sql4);
$row=mysql_fetch_assoc($sql_result4));
echo " ".$row['id']." ";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429527
Share on other sites

Ok.  Here is the updated script:

 

<?php
include 'cnt.php';
$ssn = 123456789;
$bln = "Doe";
$bor = "SELECT bor_id FROM Borrowers where ssn = $ssn AND bln = $bln";
$bor2 = mysql($bor);
$borid = mysql_fetch_assoc($bor2);
echo $borid;
?>

 

Here is what it returned:

 

Warning: Wrong parameter count for mysql() in /home/public_html/test/test.php on line 6

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/public_html/test/test.php on line 7

 

Link to comment
https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429545
Share on other sites

You cant echo arrays like you can with strings. You can use print_r to see what your array contains. To retrieve the bor_id from your query use the following:

$bor = "SELECT bor_id FROM Borrowers where ssn = '$ssn' AND bln = '$bln'";
$bor2 = mysql_query($bor);
$row = mysql_fetch_assoc($bor2);
echo $row['bor_id'];

 

 

Link to comment
https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429564
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.