Ciao a tutti, domanda un po' da gnubbo ma sono alle prime esperienze con PHP...
ho una pagina che recupera i dati da una tabella MySQL, avrei bisogno di effettuare la ricerca in base ad una selezione effettuata dall'utente, ed in particolare al periodo di riferimento; il classico da YYYY-MM-DD a YYYY-MM-DD.
Ho inserito un piccolo script Javascript all'interno del mio form che consente di selezionare le date, partenza e arrivo. Se io richiedo onClick="javascript:alert(.....);" funziona perfettamente, il dialog box presenta correttamente i valori selezionati.
Il mio problema è che non so come si fa a recuperare il valore della variabile e farlo passare al form alla pagina che poi effettua la query sul DB
Qualcuno potrebbe gentilmente aiutarmi?
posto parte del codice che ho scritto:
Codice PHP:<?php
include 'connect.php';
require_once('calendar/classes/tc_calendar.php');
?>
<HTML>
<HEAD><title>Clienti</title>
<script language="javascript" src="calendar/calendar.js"></script>
</HEAD>
<BODY>
<FORM name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>
<p class="largetxt">[b]Date Pair Example[/b]</p>
<div style="float: left;">
<div style="float: left; padding-right: 3px; line-height: 18px;">from:</div>
<div style="float: left;">
<?php
$thisweek = date('W');
$thisyear = date('Y');
$dayTimes = getDaysInWeek($thisweek, $thisyear);
//----------------------------------------
$date1 = date('Y-m-d', $dayTimes[0]);
$date2 = date('Y-m-d', $dayTimes[(sizeof($dayTimes)-1)]);
function getDaysInWeek ($weekNumber, $year, $dayStart = 1) {
// Count from '0104' because January 4th is always in week 1
// (according to ISO 8601).
$time = strtotime($year . '0104 +' . ($weekNumber - 1).' weeks');
// Get the time of the first day of the week
$dayTime = strtotime('-' . (date('w', $time) - $dayStart) . ' days', $time);
// Get the times of days 0 -> 6
$dayTimes = array ();
for ($i = 0; $i < 7; ++$i) {
$dayTimes[] = strtotime('+' . $i . ' days', $dayTime);
}
// Return timestamps for mon-sun.
return $dayTimes;
}
$myCalendar = new tc_calendar("date3", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d', strtotime($date1)), date('m', strtotime($date1)), date('Y', strtotime($date1)));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1970, 2020);
//$myCalendar->dateAllow('2009-02-20', "", false);
$myCalendar->setAlignment('left', 'bottom');
$myCalendar->setDatePair('date3', 'date4', $date2);
//$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
$myCalendar->writeScript();
?>
</div>
</div>
<div style="float: left;">
<div style="float: left; padding-left: 3px; padding-right: 3px; line-height: 18px;">to</div>
<div style="float: left;">
<?php
$myCalendar = new tc_calendar("date4", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d', strtotime($date2)), date('m', strtotime($date2)), date('Y', strtotime($date2)));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1970, 2020);
//$myCalendar->dateAllow("", '2009-11-03', false);
$myCalendar->setAlignment('left', 'bottom');
$myCalendar->setDatePair('date3', 'date4', $date1);
//$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
$myCalendar->writeScript();
?>
</div>
</div>
<input type="button" name="button2" id="button2" value="Check the value" onClick="javascript:alert('Date select from '+this.form.date3.value+' to '+this.form.date4.value);">
</p>
<hr>
</tr>
</table>
</td>
<td>
<INPUT type="submit" name="submit" value="Invia">
</td>
</tr>
</table>
</FORM>
<table width="75%" border="1">
<?php if(isset($_POST['submit'])) {
$selezione=$_POST["selezione"];
//QUI AVREI BISOGNO DI PASSARE ALL QUERY IL VALORE IMPOSTATO DALL'UTENTE.......
$sql = "SELECT * FROM student WHERE nomebiblio LIKE '%$selezione%'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
// codice PHP per popolare i dati della tabella MYSQL
}
}
?>
</table>
</BODY>
</HTML>

Rispondi quotando