$_SESSION and database records
Moderator: General Moderators
$_SESSION and database records
I'm having the hardest time trying to figure out how to get into a session a certain record from a database. I have a while loop and it prints all the database information right, but when I try to get a certain record into a $_SESSION it automatically gives me the last record inserted on the database. =s I hope I explained myself correctly I'm really struggling here... thanks
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: $_SESSION and database records
Obviously you're not doing it properly.paomoca wrote:I'm having the hardest time trying to figure out how to get into a session a certain record from a database. I have a while loop and it prints all the database information right, but when I try to get a certain record into a $_SESSION it automatically gives me the last record inserted on the database. =s I hope I explained myself correctly I'm really struggling here... thanks
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: $_SESSION and database records
yeah I kinda figured that out already ... is there anyway you could show me an example of the proper way to do it?
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: $_SESSION and database records
That was kind of a hint to post some code. Also, I have no idea what you mean by a certain record. Here is the only example I can think of, but it doesn't make much sense really:paomoca wrote:yeah I kinda figured that out already ... is there anyway you could show me an example of the proper way to do it?
Code: Select all
session_start();
while($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
$_SESSION['something'] = $rows[5];mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: $_SESSION and database records
Code: Select all
<?php
while($row = mysql_fetch_array($sqll)) {
?>
<?php $url = $row['url'];
$type = $row['type'];
$_SESSION['url'] = $url;
$_SESSION['type'] = $type;
?>
<tr>
<td><?php echo htmlentities($row['name']); ?></td>
<td><?php echo htmlentities($row['description']); ?></td>
<td>
<a href="SUA.php" target="_blank">
<?php echo $file_download; ?>
</a>
</td>
<td><?php echo $url;?></td>
<td width="10%"><?php echo $type;?></td>
Last edited by paomoca on Thu Jul 21, 2011 1:08 pm, edited 1 time in total.
Re: $_SESSION and database records
depending on the row I clic the link in I want the $_SESSION to have the values of that row... make any sense??
Re: $_SESSION and database records
If you need a php script to receive different parameters depending on the link clicked the most logical way would be to pass required parameters via GET.
Re: $_SESSION and database records
could you show me an examplee?? please
Re: $_SESSION and database records
Maybe this example will help you.
Link:
PHP:
This is more than likely not 100% yours, but it's a very good window to show how something like that can be achieved. I hope this snippet helps you.
Link:
Code: Select all
<a href="http://mydomain.com/index.php?session=mysession" name="mysession">My Link</a>Code: Select all
<?php
// include the file you connected to the db with
require './assets/connect.php';
// get the information sent over from the link
$mysession = $_GET['session'];
// check if the session is retrieved from the url via the link clicked
if(isset($mysession)) {
// use a mysql query to retrieve the session from the database
$getsession = mysql_query("SELECT `session` FROM `session_table` LIMIT 1") or die(mysql_error());
// check if the session from the link matches the session from the database
// if it doesn't, then disreguard the session
$rows = mysql_num_rows($getsession);
if($rows != 1) {
// loop through the sessions
while($row = mysql_fetch_assoc($getsession) {
// set var to get value from the `session` cell of the table
$session = $row['session'];
// set the session based on the session pulled from the table
$_SESSION['my_session'] = $session;
}
} else {
echo 'No Match';
}
}
?>- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: $_SESSION and database records
thanks I'll try that It's from a free script I got I'm just trying to edit it to fit my needs =)