Log in

View Full Version : echo problem? can't select my data from mysql table



madkixt
11-24-2008, 11:16 AM
hello guru(s) and advance i have any problem with $_session

can help me more for solution my problem.

i use this code select.php


<?php
session_start();
include("../dbconfig.php");

$examp = $_GET["q"]; //query number

$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
.................
search code ...................
................
$idm = $_SESSION['id'];
//SQL Statement
$SQL = "SELECT * FROM
tb_profile A
INNER JOIN
tbc_divisi B
ON
A.id_divisi = B.id_divisi
INNER JOIN
tbc_status_aktif C
ON
A.id_statusaktif = C.id_statusaktif
WHERE id_p = ".$idm." ".$wh." ORDER BY ".$sidx." ". $sord." LIMIT ".$start." , ".$limit;
...................
//SQL Query Statment
...................
?>


i cant echo $idm;

so i can't select my data from mysql table...

can i use $_SESSION for this situation or anything else ??

thx before.. please help me...

JasonDFR
11-30-2008, 07:26 PM
Try using a " to close your $sql = statement after $limit ( $limit" ; )

Why are you concatenating all the variables in the $sql string? I don't think you need to.

Try:


$SQL = "SELECT * FROM
tb_profile A
INNER JOIN
tbc_divisi B
ON
A.id_divisi = B.id_divisi
INNER JOIN
tbc_status_aktif C
ON
A.id_statusaktif = C.id_statusaktif
WHERE id_p = '$idm'.'$wh' ORDER BY '$sidx'.'$sord' LIMIT $start , $limit" ;

Actually, as I was putting this together, I realized I have no idea how the dark red portion of the above $sql string works.

Repost the string with sample values. Like you would if you were using the MySQL command line or typing a query into phpmyadmin.

I really don't think you need all those quotes in your string though. When putting integers into a mysql query, you shouldn't put quotes around them. (if you are using integers for id_p, etc)

Jason

JasonDFR
11-30-2008, 07:32 PM
And for your $_SESSION variables in the query, you can do:


$q2 = "UPDATE `table`
SET `column` = 'string'
WHERE `column` = {$_SESSION['X']} LIMIT 1 " ;

The above syntax is, strictly speaking, the most correct.