I'm using PHP in combination with an Oracle database. What I want is the following: On the first form I want to select a name out of a table in the database and when you push the button open I want the users to see a html form where the fields are filled in with the information from the person you've selected on the first screen. You can edit this information and when you push the update button the table has to be updated. I don't know who to do this whole process in PHP in combination with Oracle. Can someone please help me? This is an important part of a project I'm doing and I can't find any information anywhere!
I really hope someone can help me.
PHP & Oracle database edit/update data.
geting error Undefined variable: objResult on <<<-----here
<?
$objConnect = oci_connect("myuser", "mypassword", "TCDB");
$strSQL = "SELECT * FROM CUSTOMER";
$objParse = oci_parse($objConnect, $strSQL);
oci_execute($objParse, OCI_DEFAULT);
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
<th width="30"> <div align="center">Edit </div></th>
</tr>
<?
while ($objResult = oci_fetch_array($objParse, OCI_BOTH))
{
?>
<tr>
<td><div align="center"><?= $objResult["CUSTOMERID"]; ?></div></td> <<---here
<td><?= $objResult["NAME"]; ?></td> <<---here
<td><?= $objResult["EMAIL"]; ?></td> <<---here
<td><div align="center"><?= $objResult["COUNTRYCODE"]; ?></div></td>
<td align="right"><?= $objResult["BUDGET"]; ?></td> <<---here
<td align="right"><?= $objResult["USED"]; ?></td>
<td align="center">Edit</td>
</tr>
<?
}
?>
</table>
<?
oci_close($objConnect);
?>
Your while loop will probably only work for the first line. Make sure you use { } for every loop, be it one line or many.
This error could mean that short_open_tag isn't enabled in your php.ini, and due to that PHP actually sees no code in your template. Only the <?= ... ?> tags are working, while the <? ... ?> are not.
Your options:
Set short_open_tag = On in your php.ini. Or,
use full <?php ... ?> tags instead
Also, the while loop isn't complete. Try:
<?
while ($objResult = oci_fetch_array($objParse, OCI_BOTH)):
?>
// ...
<?
endwhile;
?>
Related
I have a query that returns me a long series of questions and answers. in my html page I have div that alternate with slider effect. so far everything is fine. at the moment I try to correctly display a question from the db bumps everything. why?
<div align=Center>
<br/>
<h1><?php echo $rowfirst['Cognome']." ".$rowfirst['Nome']; ?></h1>
<br/>
<div class="nivo-slider">
<div class="navigation"></div>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<div id="nivo">
<div class="element" align=Center><h3>Anamnesi pregressa</h3>
<table class="w3-table w3-bordered " style="width:400px;padding:10px;" align="center">
<tbody>
<tr>
<th scope="row"><?php echo $row['testo'];}?></th>
<td>risposta 1</td>
</tr>
</tbody>
</table>
</div>
<div class="element" align=Center><h3>Scrittura</h3>
<table class="w3-table w3-bordered" style="width:400px;padding:10px;" align="center">
<tbody>
<tr>
<th scope="row">domanda 1</th>
<td>risposta 1</td>
</tr>
</tbody>
</table>
</div>
<div class="element"><h3>Motricità</h3>
<table class="w3-table w3-bordered " style="width:400px;padding:10px;" align="center">
<tbody>
<tr>
<th scope="row">domanda 1</th>
<td>risposta 1</td>
</tr>
</tbody>
</table>
</div>
</div>
<br/>
</div>
</div>
The problem is the while. cycle. how can I solve it?
What you have will create malformed HTML.
In order to prevent malformed HTML, you should place your while () { and } where the tags matches like I have done with <tr> and </tr> shown below:
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<th scope="row"><?php echo $row['testo'];?></th>
<td>risposta 1</td>
</tr>
<?php } ?>
That will fix your malformed HTML but the while statement may or may not be in the right place and without knowing exactly what you are trying to achieve you'll have to correct it from there. As for the slider you mentioned, you probably need to supply more information if this answer doesn't solve your issue.
Not sure if this is the best way to do this.. But..
I've got a PHP file calling an API and doing a foreach loop to get all the data I want. Previously I was calling this from my html file and putting it into a table, the problem was that it was all appearing as technically the same row and that made formatting hard.
This is what I used to have:
<div class="bgimg2 w3-container">
<table class="w3-table w3-medium w3-text-white">
<tr class="w3-blue-gray">
<th> <h5> Name </h5> </th>
<th> <h5> Size </h5> </th>
<th> <h5> % </h5> </th>
</tr>
<tr>
<th> <h4> <div id=queue> </h4> </th>
<th> <h4> <div id=queueSize> </h4> </th>
<th> <h4> <div id=queuePercent> </h4> </th>
</tr>
</thead>
</table>
</div>
I want to have each item appearing as it's own row, so I'm trying to do a php foreach loop directly in the table.
This is what I've got currently for the table:
<table class="w3-table w3-medium w3-text-white">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<?php
require_once ('/api/sabapiQueue.php');
foreach ($apiResultDataShift as $row){
?>
<tr>
<td> <?php $row['filename'] ?> </td>
</tr>
<?php } ?>
</tbody>
</table>
It's not working and the file isn't even loading. Not sure where I've gone wrong.
Any help would be greatly appreciated.
Seems you missed a detail in not echoing out your variable. I would also suggest, and perhaps introduce you to alternative PHP syntax which is good for when you want to tightly integrate a few php blocks into html as you are doing here:
<table class="w3-table w3-medium w3-text-white">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<?php
require_once ('/api/sabapiQueue.php');
foreach ($apiResultDataShift as $row):
?>
<tr>
<td><?= $row['filename'] ?></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
Alternatively, as per the echo manual page you could just change this line:
<td><?php echo $row['filename']; ?></td>
I new to php and learning and need some advice on shoing my database info within a loop which includes html, My page is blank so am wondering why my php isnt valid:
<?php include 'incudes/connect_db.php'; ?>
<div class="topbar">
<div class="topbarblock1">Dashboard</div>
<div class="topbarblock2">Username</div>
</div>
<br><br>
<div class="middle">
<div class="middleblock1">Dashboard</div>
<div class="middleblock2">
<div class="container">
<?php
$result = mysqli_query($con,"SELECT * FROM users");
while($row = mysqli_fetch_array($result)) {
?>
<h2>
User Management
<hr />
</h2>
</div>
<div class="containermain">
<table>
<tr>
<th class="th1">User Id</th>
<th class="th2">Username</th>
<th class="th3">Email Address</th>
<th class="th4">Details</th>
</tr>
<tr>
<td class="td1">#</td>
<td class="td2"><?php echo $row['username']; ?></td>
<td class="td3"><?php $row['email']; ?></td>
<th class="td4">Edit</th>
</tr>
</table>
</div>
</div>
</div>
<?php
}
?>
I'm not looking for a straight out answer I am looking for some advice on how this should be laid out and learn best practices.
Change the line that says
<td class="td3"><?php $row['email']; ?></td>
to
<td class="td3"><?php echo $row['email']; ?></td>
PHP will try to interpret the variable as some sort of command/statement otherwise and subsequently fail.
Also rethink where you wrap the loop as I previously mentioned, or else your HTML is going to end up wonky (you'll see this after you've fixed the code.)
You should also program by using error_reporting(E_ALL); at the start of your code so you can fix simple mistakes on your own
I have a database of players and their info in mysql. I have created a table in dreamweaver displaying all the players and their info. I want to display a player profile (which is stored in mysql) seperate from this table and want this information to change when the mouse is over a player in the table.
Is this possible and how do i go about it? Any help or links to tutorials will be greatly received!
I have a Screenshot of my page but am unable to post due to reputation if anyone wants to visualise my idea maybe i could send it them?
<div class="playerInfoContainer">
<table width="95%" border="0" cellpadding="3">
<caption>
Player Profile
</caption>
<tr>
<td><?php echo $row_Recordset1['PlayerProfile']; ?></td>
</tr>
</table>
</div>
</div>
<div class="squadListContainer">
<div class="DatabaseContainer">
<table width="95%" border="0" cellpadding="3">
<caption>
Bedlinog Veterans Squad
</caption>
<tr>
<th scope="col">Player Name</th>
<th scope="col">Position</th>
<th scope="col">Date of Birth</th>
<th scope="col">Points Tally</th>
<th scope="col">Man of the Matches</th>
</tr>
<?php do { ?>
<tr>
<td width="130"><?php echo $row_Recordset1['PlayerName']; ?></td>
<td width="100"><?php echo $row_Recordset1['Position']; ?></td>
<td width="100"><?php echo $row_Recordset1['DateOfBirth']; ?></td>
<td width="100"><?php echo $row_Recordset1['PointsTally']; ?></td>
<td width="100"><?php echo $row_Recordset1['MOM']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</div>
Firstly, pre-build all of the displayed mouse-over data into separate XML/JSON files. That way there's no load on a database to display 15 items at once when someone goes nuts with their cursor.
Secondly, use jquery to display a mouseover event to populate a div on the page with the separate HTML files.
As long as your jquery is correct and your css skills are up to snuff, the details will change as required and maintain the correct look/feel as it goes from one 'team/squad' to the next.
I'm trying to use this chart generator from http://htmldrive.net/items/show/792/Rare-Accessible-charts-using-jQuery-and-HTML5.html
Here's the code which loads data from mysql database:
The query works, but I guess my interpretation of the example provided in the site was wrong.
I get an output if I do it this way(predefined data):
<tr>
<th scope="row">Profit</th>
<td>5</td>
<td>5</td>
</tr>
But when I do it this way I get a blank output:
?>
<table>
<caption> Reports</caption>
<thead>
<tr>
<td></td>
<?php while($row=mysql_fetch_assoc($query)){ ?>
<th scope="col"><?php echo $row['Cust_Name']; ?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Subtotal</th>
<?php while($row=mysql_fetch_assoc($query)){ ?>
<td><?php echo $row['TOTAL_PUR']; ?></td>
<?php } ?>
</tr>
<tr>
<th scope="row">Profit</th>
<?php while($row=mysql_fetch_assoc($query)){ ?>
<td><?php echo $row['TOTALPROFIT']; ?></td>
<?php } ?>
</tr>
</tbody>
</table>
Here's what I'm getting:
After the first iteration through the rows, when you display the customer names, the fetch data pointer is at the end of the dataset... you're trying to fetch the set again without resetting the pointer.
Try issuing
mysql_data_seek($query, 0);
before the while loops to display total and profit