Jump to content

Need help in query


Recommended Posts

Hello, currenly I am working on a query page and need help in fixing my query code. My php query scripts are located before html file so I put an echo command at the html table but what happen was that the data that shown up is only the last data in the database table (I think I should modify the query or put a loop inside echo command but I do not know how to do it). So can someone help me with the query?

As you can see below is the original code but I need to move the echo into dreamweaver table and keep it looping and showing the woled data in query and not only the last one. pleae help thanks

 

 

<?

session_start();

if (!isset($_SESSION['login']))

{

header('Location:http://localhost/wip/index.html');

}

 

 

$conn=odbc_connect('jascon','root','admin');

if (!$conn)

{exit("Connection Failed: " . $conn);}

$sql="SELECT * FROM user_case_data";

$rs=odbc_exec($conn,$sql);

if (!$rs)

{exit("Error in SQL");}

 

while (odbc_fetch_row($rs))

{

$compname=odbc_result($rs,"case_num");

$conname=odbc_result($rs,"case_outcome");

 

echo "$compname";

echo "$conname";

}

odbc_close($conn);

echo "</table>";

 

 

session_destroy();

?>

 

 

Link to comment
Share on other sites

Hey Jacob, check this and see if it'll work for ya. I tried to add some comments.

 

<?php

session_start();

if (!isset($_SESSION['login']))

{

header('Location:http://localhost/wip/index.html');

}

$conn=odbc_connect('jascon','root','admin');

if (!$conn)

{exit("Connection Failed: " . $conn);}

$sql="SELECT * FROM user_case_data";

$rs=odbc_exec($conn,$sql);

if (!$rs)

{exit("Error in SQL");}

 

//exit out of php to create table

?>

<table>

<?php //go back into php to start loop

 

while (odbc_fetch_row($rs))

{

 

//exit again to fill in values

?>

<tr>

<td><?php echo odbc_result($rs,"case_num"); ?></td>

<td><?php echo odbc_result($rs,"case_outcome") ?></td>

</tr>

 

<?php //back in php to close out the loop

}

odbc_close($conn);

 

// and back out of php again to close the table

?>

</table>

 

<?php

session_destroy();

?>

 

-jeremy

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.