id not going through the url - php

my id is not going through the url. my code is as follows
<?php
include 'library/connect.php';
$result = mysql_query("SELECT * FROM meetings ");
echo "<table border='1'><tr><th>Title</th><th>Chairman</th><th>Secretary</th><th>Terms of Reference</th><th>Named membership</th><th>Occurences</th><th>Book Room</th></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['title']. "</td>";
echo "<td>" . $row['chairman']. "</td>";
echo "<td>" . $row['secretary']. "</td>";
echo "<td>" . $row['termsOfReference']. "</td>";
echo "<td>" . $row['named_membership']. "</td>";
echo "<td>" . $row['occurences']. "</td>";
?>
<td><font color="#CC3300">Book: room/date/time</font></td>
<?php
}
echo "</tr>";
echo "</table>";
include 'library/closedb.php';
?>
have you got any idea of what the problem can be?

where is $meeting_id set? seems to me like it should be $row['meeting_id'].

Where $meeting_id is defined?
It seems like you did a select but forgot to retrieve the meeting id.
Try to change the link to:
<a href ="secretary_booksRoom.php?meeting_id=<?php echo $row['meeting_id']; ?>">
In case you have column named meeting_id in your table of course.

<tr> tag need to be closed in the while loop

You need to define the $meeting_id variable before adding it to the URL, otherwise your link will simply be "secretary_booksRoom.php?meeting_id=". I am going to assume that your meetings table has an id column as a primary key. In your while loop, try declaring "$meetind_id = $row['your meeting id column']". This should get the meeting id and pass it to the URL.
Hope this helps.

Related

Why is only one row from this query displayed?

I am trying to print the results of this query, but it only prints out the first row. Why is that?
if (isset($_GET['consumiperstanza'])) {
$num_stanza=$_GET['num_stanza'];
$data1=$_GET['data1'];
$data2=$_GET['data2'];
$query="SELECT stanze.num_stanza,consumi.cod_consumo, servizi.nome,
consumi.quantita, servizi.prezzo, consumi.data_c
FROM consumi, servizi, stanze
WHERE stanze.num_stanza=consumi.num_stanza
AND servizi.cod_servizio=consumi.cod_servizio
AND stanze.num_stanza='$num_stanza'
AND consumi.data_c BETWEEN '$data1' AND '$data2'
GROUP BY stanze.num_stanza";
$risultato = $conn->query($query);
if(mysqli_num_rows($risultato) > 0){
echo "<table border=1 bgcolor= 'white' align='center'>";
echo "<tr>";
echo "<th>NUMERO STANZA</th>";
echo "<th>CODICE CONSUMO</th>";
echo "<th>NOME</th>";
echo "<th>QUANTITÀ</th>";
echo "<th>PREZZO</th>";
echo "<th>DATA</th>";
echo "</tr>";
while($riga = mysqli_fetch_array($risultato)){
echo "<tr>";
echo "<td>" . $riga[0] . "</td>";
echo "<td>" . $riga[1] . "</td>";
echo "<td>" . $riga[2] . "</td>";
echo "<td>" . $riga[3] . "</td>";
echo "<td>" . $riga[4] . "</td>";
echo "<td>" . $riga[5] . "</td>";
echo "</tr>";
}
echo "</table><br>";
}
}
This is part of your criteria
AND stanze.num_stanza='$num_stanza'
But you're also doing this.
GROUP BY stanze.num_stanza
So, you'll only get one group.
Additionally, all the other columns in your SELECT are not well-defined since they are not included in the GROUP BY and are not aggregate expressions. Newer versions of MySQL actually will not allow you to do this by default. It is possible in older versions, but may not give you the results you expect.
The MySQL 5.6 manual:
... this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are nondeterministic.

Read More Button

I have the below table in my site...
and what I want is that when i click on the read more link to redirect me to the page view_announcement.php and in this page to display me the whole data for this specific row.
For example, if we click on the link in the second row I want in the view_announcement.php to load all the data for this specific row.
My code in order to display this table is this...
<?php
$q = ($_GET['q']);
$con = mysqli_connect('localhost','root','smogi','project');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"project");
$sql="SELECT author,category,subject,content FROM announcements WHERE category = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>Author</th>
<th>Category</th>
<th>Subject</th>
<th>Content</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['author'] . "</td>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . $row['subject'] . "</td>";
echo "<td>" . 'Read More' . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
The view_announcement.php file doesn't contain any code yet because i dont know what to write.
One way to do it is to append a query variable to the "Read More" links. You'll probably need a unique identifier, such as an ID number, on your announements table. If you don't have one yet, I suggest adding one and setting it up to auto-increment.
You would want to modify your query to include the unique ID number:
$sql="SELECT id,author,category,subject,content FROM announcements WHERE category = '".$q."'";
Then you would modify the loop which prints your table out to include those unique IDs in the URL to view_announcement.php
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['author'] . "</td>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . $row['subject'] . "</td>";
echo "<td>" . 'Read More' . "</td>";
echo "</tr>";
}
And in your file view_announcement.php, you would make another SQL query to get the full data for a specific row, like this:
$sql="SELECT * FROM announcements WHERE ID = '".$_GET['id']."'";
If you click any button, that redirects to view_announcement.php file, where you can get the subject values.
Use that subject values in your query to get all the details which relates to that subject.

How to put user input into a SQL Query

I have a database and I want the user to be able to have an input into what comes out. i.e
Select from Table where example = user input from box **(input by the user)**
Im guessing what I need is a variable to hold the value that then goes into the statement. I know how to get the value from the input box with script but can I use it like:
select * From handover WHERE hdate = variable. However I am guessing someone is going to talk to me about security if its even possible.
<html><body>
<input>User input</input> //That needs to go into statement
<?php
include 'config.php';
$result = mysqli_query($con,"SELECT * FROM handover WHERE hdate = **user input**;");
echo "<table border='1'>
<tr>
<th>hdate</th>
<th>Delay</th>
<th>Health and Safety</th>
<th>Non Vsa</th>
<th>VSA</th>
<th>Dar</th>
<th>Other</th>
<th>Hour</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['hdate'] . "</td>";
echo "<td>" . $row['hdelay'] . "</td>";
echo "<td>" . $row['hs'] . "</td>";
echo "<td>" . $row['nv'] . "</td>";
echo "<td>" . $row['vsa'] . "</td>";
echo "<td>" . $row['dar'] . "</td>";
echo "<td>" . $row['other'] . "</td>";
echo "<td>" . $row['hour'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Any help is welcome and advice on the best language to use for this.
Kind Regards
Fintan
first of all, this question has nothing to do with javascript & ajax. so you can delete those tags.
you want to show/search data from mysql.
$result = mysqli_query($con,"SELECT * FROM handover WHERE hdate = '".$_POST['abc']."' ");
this is when you want to check if hdate column have exact data as user input ( $_POST['abc'] ).
and also don't forget to use mysqli_real_escape_string
you can learn common mysql pattern queries from here: http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html

How to put a break in the output when specific values change using mysqli php

I am building a website to list statistics for bowling tournaments over the last 24 years. Using the following code generates a long, single table showing all the data. I would like to put a break in the table when the $row['season'] value changes, i.e., from 1990-1991 to 1991-1992, and for each subsequent change of seasons and echo either an html horizontal line between seasons or put the value of the season from the database, i.e., 2013-2014 at the top of each table segment. After a week of searching the web haven't figured out an answer. Here's the code I have now. Needs to be mysqli.
$result = mysqli_query($conn,"SELECT * FROM members INNER JOIN scores ON members.id=scores.memberID WHERE format LIKE '%s%' ORDER BY year, STR_TO_DATE( month, '%b' ), format ASC;");
echo "<table border='0'>
<tr>
<th>Name</th>
<th>Hometown</th>
<th>Month</th>
<th>Year</th>
<th>Season</th>
<th>Center</th>
<th>Center City</th>
<th>Format</th>
</tr>";
foreach($result as $row) {
echo "<tr>";
echo "<td>" . $row['firstName'] . " ". $row['lastName'] . "</td>";
echo "<td>" . $row['hometown'] . "</td>";
echo "<td>" . $row['month'] . "</td>";
echo "<td>" . $row['year'] . "</td>";
echo "<td>" . $row['season'] . "</td>";
echo "<td>" . $row['center'] . "</td>";
echo "<td>" . $row['centerCity'] . "</td>";
echo "<td>" . $row['format'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
The answer is actually already given but it looks like your new with php so here is a smal example i hope its useful to you.
You need to insert some if statements to check if there is any change of year. same goes for any other checks you want to perform.
this is something you could do...
<?php
$lastYear = null;//you can also set the first year manually of course
foreach($result as $row) {
//set the first year
if($lastYear == null){$lastYear = $row['year'];}
//check if the year changed or not
if($lastYear == $row['year']){
//if the year didnt change... do something
}else{
//your year changed... do something different
$lastYear = $row['year']; //update your 'last'year
}
}
?>
I hope this will help you.

php mysql echo | How to inherit colors from a submit form?

I'm having some real trouble finding information on this topic and I would be very appreciative for any help. In short I have a form where users select a category from a drop down list, enter some contents, and hit submit which goes to SQL. Each category in the dropdown is color coded:
<option STYLE="color: #00CC66;" value="Option_1">Option_1</option>
<option STYLE="color: #0066CC;" value="Option_2">Option_2</option>
<option STYLE="color: #996633;" value="Option_3">Option_3</option>
etc
Then I have a php that pulls up the stored submitted data (categories and contents) into a table on that same page sorted by date.
<?php
$con=mysqli_connect("localhost","myuser","mypassword","mydb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM mytable order by date DESC");
echo "<table border='1'>
<tr>
<th>Category</th>
<th>Contents</th>
<th>Date/Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . $row['contents'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
My question is, when echo places the information in the table, is there a way I can get 'category' showing up in the same colors as the user form? (IE, on the table, Option_1 would show up as #00CC66, Option 2 as 0066CC, etc...)
Basically I want the actual category text on the fetched table to display the same as it is in the drop down form. I don't mind if I need to manually set each one as the categories are limited, I just have no clue where to begin on this one. Appreciate any help in advance!
Yes, but you would need to either change the value of the select box to the colour or manually do it like this:
function getColor($strOption)
{
switch ($strOption)
{
case "Option_1":
return "#00CC66";
case "Option_2":
return "#0066CC";
#etc
}
}
Then in your while loop:
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><font color='".getColor($row['category'])."'> " . $row['category'] . "</font></td>";
echo "<td>" . $row['contents'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}

Categories