Hello guys I have a query that need a variable to be executed but that variable is returned by a select on a form
$obtermaxcampo = "SELECT P$pagina as maxcampo FROM slider_settings where ID = $ID";
if I define $pagina = 1 it only query me the P1 and I have 12 P's.
My question is if theres any way to start the variable in 1 but after submit delete that definition and give him a $pagina = $_POST['selectedPagina'];
here is the selected form
<form action="" method="POST" name="carregarinfo">
<label>Pagina</label>
<select name ="selectedPagina" id="selected" >
<?php for ($k = 1; $k <= $result['max']; $k++){?>
<option value ="<?php echo $k;?>" <?php if($_POST['selectedPagina'] == $k){echo "selected='$k'"; }?>><?php echo $k;?></option>
<?php
}
?>
</select>
<label>Campo</label>
<select name ="selectedCampo" id="selected" >
<?php for ($z = 1; $z <= $resultmaxcampo['maxcampo']; $z++){?>
<option value ="<?php echo $z;?>"><?php echo $z;?></option>
<?php
}
?>
</select>
<input type="submit" name="carregar" id="carregar" value="Carregar">
</form>
if(isset($_POST['carregar'])){
$sql = "SELECT tituloP$pagina as titulopag, Butao, Titulo, Texto FROM slider_settings, slider_config where slider_settings.ID = $ID and slider_config.P_NUM = $pagina and slider_config.Campo = $campo and slider_config.ID = $ID";
$sqlconnect = $connect->query($sql);
$sqlresult = $sqlconnect->fetch_assoc();
$pagina = $_POST['selectedPagina'];
$obtermaxcampo = "SELECT P$pagina as maxcampo FROM slider_settings where ID = $ID";
$connectionmaxcampo = $connect->query($obtermaxcampo);
$resultmaxcampo = $connectionmaxcampo ->fetch_assoc();
}
Related
in my code I'm trying to display in a text box the record that follows the last one of my database. For example, if my last record is A560 I want to display A561. To achieve this I know I have to split the record and then manipulate it, but I haven't had any luck. Here is what the database looks like:
Point_ID Project No. Project Manager Comments
A558 1304 Oscar Duran Found destroyed
A559 1304 Oscar Duran Helicopter access
A560 1356 Julio Bravo Airport parking lot
This is my code so far:
#{
Layout = "~/_Layout.cshtml";
var db = Database.Open("ControlPoints");
var SelectCommand = "SELECT * FROM( SELECT TOP 5 * FROM AllControlMergedND WHERE Point_ID LIKE 'A___' ORDER BY Point_ID DESC )AS BaseData Order BY Point_ID ASC";
var SearchTerm = "";
if(!Request.QueryString["SearchCP"].IsEmpty() ){
SelectCommand = "SELECT * FROM AllControlMergedND WHERE Point_ID = #0";
SearchTerm = Request.QueryString["SearchCP"];
}
if(!Request.QueryString["SearchProject"].IsEmpty() ){
SelectCommand = "SELECT * FROM AllControlMergedND WHERE [Project Used on] LIKE #0";
SearchTerm = "%" + Request["SearchProject"] + "%";
}
var SelectData = db.Query(SelectCommand, SearchTerm);
var grid = new WebGrid(source: SelectData, rowsPerPage: 10);
}
#{
Validation.RequireField("Point_ID", " Required");
Validation.RequireField("ProjectNo", " Required");
Validation.RequireField("ProjectManager", " Required");
var Point_ID = "";
var ProjectNo = "";
var ProjectManager = "";
if(IsPost && Validation.IsValid() ){
Point_ID = Request.Form["Point_ID"];
ProjectNo = Request.Form["ProjectNo"];
ProjectManager = Request.Form["ProjectManager"];
db = Database.Open("ControlPoints");
var InsertCommand = "INSERT INTO AllControlMergedND ([Point_ID], [Project No.], [Project Manager]) VALUES(#0, #1, #2)";
db.Execute(InsertCommand, Point_ID, ProjectNo, ProjectManager);
}
var SelectLastCP = "SELECT TOP 1 Point_ID FROM AllControlMergedND WHERE Point_ID LIKE 'A___' ORDER BY Point_ID DESC";
var SelectData2 = db.QuerySingle(SelectLastCP);
var SuggestedPoint_ID = SelectData2.Point_ID;
}
<h2>Airborne Imaging Control Points Database</h2><br/><br/>
<form method="get">
<fieldset>
<legend>Search Criteria</legend>
<div>
<p><label for="SearchCP">Control Point ID:</label>
<input type="text" name="SearchCP" value="#Request.QueryString["SearchCP"]" />
<input type="submit" value="Search"/></p>
</div>
<div>
<p><label for="SearchProject">Project:</label>
<input type="text" name="SearchProject" value="#Request.QueryString["SearchProject"]" />
<input type="Submit" value="Search" /></p>
</div>
</fieldset>
</form>
<div>
#grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("Point_ID"),
grid.Column("Project No."),
grid.Column("Project Used on"),
grid.Column("WGS84 Lat"),
grid.Column("WGS84 Long"),
grid.Column("Ellips_Ht"),
grid.Column("Project Manager"),
grid.Column("Comments")
)
)
<br/><br/>
</div>
<form method="post">
<fieldset>
<legend>Create Control Point(s)</legend>
<p><label for="Point_ID">Point ID:</label>
<input type="text" name="Point_ID" value="#SuggestedPoint_ID" />
#Html.ValidationMessage("Point_ID")</p>
<p><label for="ProjectNo">Project No:</label>
<input type="text" name="ProjectNo" value="#Request.Form["ProjectNo"]" />
#Html.ValidationMessage("ProjectNo")</p>
<p><label for="ProjectManager">Project Manager:</label>
<input type="text" name="ProjectManager" value="#Request.Form["ProjectManager"]" />
#Html.ValidationMessage("ProjectManager")</p>
<p><input type="submit" name="ButtonConfirm" value="Confirm" /></p>
</fieldset>
</form>
As you can see, all I am able to do is to display the last record of my database in the text box, which in this case would be A560. The variable 'SuggestedPoint_ID' is holding that record. I have tried converting the data type, but had no success. Any help would be greatly appreciated.
Update:
What I need is to do the following. Split A560 in two parts 'A' and '560'. Then increment '560' by one to obtain '561' and finally attach 'A' again to '561' in order to obtain the next increment 'A561'.
If you are trying to convert "A560" to int for example then it won't work because you don't have a valid number. A needs to be removed.
var SuggestedPoint_ID = SelectData2.Point_ID.Replace("A", "");
This is not my recommended way to do it as A could be anything such as AA or B or ZZZZ. My point is that you need to describe what you need to get a better solution to your problem.
UPDATE
var source = "A560";
var lhs = source.Substring(0, 1);
var tmp = source.Replace(lhs, "");
int rhs;
if(int.TryParse(tmp, out rhs))
{
rhs++;
}
var result = string.Format("{0}{1}", lhs, rhs);
I want to echo a div only once in a Clistview, the items are order by status, so, i want to print status 1 -> all the items, and then status 2 -> all the items with that status, I tried viewData, but I dont know how to change the value of the flag.
INDEX VIEW:
<div class="modal-body">
<?php
$activos_flag = 1;
$inactivos_flag = 1;
?>
<?php
$this->widget('zii.widgets.grid.CListView', array(
'id'=>'incs',
'summaryText'=>'',
'dataProvider'=>$dataProviderInc,
'itemView'=>'_incidencias',
'viewData'=> array('activo'=> $activos_flag,'inactivo'=>$inactivos_flag),
));
?>
</div>
_INCIDENCIAS VIEW:
<?php
if ($data->activo == 1 and $data->incidencia_estado == 1){
echo ('<label class="incidencias">ACTIVOS</label>');
$data->activo = 0;
}
if ($data->inactivo == 1 and $data->incidencia_estado == 0){
echo ('<label class="incidencias">INACTIVOS</label>');
$data->inactivo = 0;
}
?>
You need to get the value not from the array $data ($data->inactivo) but directly from a variable $inactivo. But in any case, at each iteration, the value of these variables will again be equal to 1. In this case, you can use the following approach:
Before widget declaration:
Yii::app()->params['activos_flag']=1;
Yii::app()->params['inactivos_flag']=1;
and in parial view:
if ( Yii::app()->params['activos_flag'] == 1 ){
echo ('<label class="incidencias">ACTIVOS</label>');
Yii::app()->params['activos_flag'] = 0;
}
if ( Yii::app()->params['inactivos_flag'] == 1 ){
echo ('<label class="incidencias">INACTIVOS</label>');
Yii::app()->params['inactivos_flag'] = 0;
}
How can I connect my php code to MySQL database?
I have tried many times and it cannot access the database.
These are the codes in my php file:
<html>
<head>
<title>Brandon's Search Engine - Results</title>
</head>
<body>
<h2>Brandon's Search Engine</h2>
<form action='./search.php' method='get'>
<input type='text' name='k' size='80' value='<?php echo $_GET['k']; ?>' />
<input type='submit' value='Search' >
</form>
<hr />
<?php
$k = $_GET['k'];
$terms = explode(" ", $k);
$query = "SELECT * FROM search WHERE ";
foreach ($terms as $each){
$i++;
if ($i == 1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= "OR keywords LIKE '%$each%' ";
}
// connect
mysql_connect("sql102.freezoy.com", "frzoy_13854016", "xxxx");
mysql_select_db("frzoy_13854016_search");
$query = mysql_query($query);
$numrows = $query->num_rows;
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query)){
$id = $row('id');
$title = $row('title');
$description = $row('description');
$keywords = $row('keywords');
$link = $row('link');
echo "<h2><a href='$link'>$title</a></h2>
$description<br /><br />";
}
}
else
echo"No results found for \"<b>$k</b>\"";
// disconnect
mysql_close();
?>
</body>
</html>
I have insert some data into the database.
Please help. Thanks in advance.
I am a student and also working in my university. I am not studying computer science.
I mainly do support stuff, but now I should take care of our internship database.
Task: Create a drop down menu from a town which a student choses, then show all internships in this town.
I have an existing SQL database, can create a drop down menu from it, but have NO idea how I can use the selected value. A submit button would be fine, any solution which works is fine.
How can I put the chosen value from drop down menu to a PHP variable?
<?php
$dbanfrage = "SELECT DISTINCT Stadt FROM $tabelle WHERE Land = 'China' OR Land = 'Taiwan' OR Land = 'VR China' ORDER BY STADT ";
$result = mysql_db_query ($dbname, $dbanfrage, $dbverbindung);
if (!$result)
{
$message = 'Ungültige Abfrage: ' . mysql_error() . "\n";
$message .= 'Gesamte Abfrage: ' . $dbanfrage;
die($message);
}
echo "<select>";
echo "<option>Stadt auswählen</option>"; // printing the list box select command
while($nt = mysql_fetch_array($result)) //Array or records stored in $nt
{
echo "<option value = $nt[id]>$nt[Stadt]</option>"; /* Option values are added by looping through the array */
}
echo "</select>"; // Closing of list box
mysql_close ($dbverbindung);
?>
Just suggesting how you can do it --
<select name="country" id="country" onChange="showState();" >
<option value="">Select Country</option>
<option value="1">India</option>
<option value="2">Nepal</option>
</select>
Your Script--
<script type="text/javascript">
function showState( )
{
var value = document.getElementById('country').value;
var url = '<?php echo base_url ?>showstate.php';
$.ajax({
type: "GET",
url: url,
data:{'country':value},
success:function(results)
{
$('#div_state').html(results);
}
});
}
</script>
Your showstate.php php page --
//INCLUDE CONNECTION file to for db query
$type = $_GET['country'];
//Your DB QUERIES
This will load the content in your #div_state div. You can also use Jquery For this..i think this will help you :) an d let me know if you have any query.
<select name="name">
<option value="select">select</option>
<?php
$dbanfragee=mysql_query("SELECT DISTINCT Stadt FROM $tabelle WHERE Land = 'China' OR Land = 'Taiwan' OR Land = 'VR China' ORDER BY STADT ");
while($row=mysql_fetch_array($$dbanfrage)){?>
<option value="<?=$row['id']?>"><?=$row['stadt']?></option>
<?php }?>
</select>
I have the following function written in function.php in a wordpress theme
function get_mms($my_post) {
$post_id = $my_post; //$_GET["p"];
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
preg_match_all('#\[mms\](.+)\[\/mms\]#', $queried_post->post_content, $matches);
echo 'EN: ' . $matches[1][0];
echo '<br><br><form action= " ' . get_permalink( $id ) . ' " method="post">
Numar: <input type="text" name="fname" />
<input name="submito" type="submit" />
</form>';
$numero = $_POST["fname"];
if(isset($_POST['submito'])&& $_POST['fname']){
$numero = $_POST["fname"];
header("Location: http://server/&to=$numero&text='.$matches[1][0].'&from=Moldcell");
}
When I submit the form instead of getting the value of $matches[1][0] I get Array[0].
Is there someting I did wrong? What can I do to make it grab the value of preg_match_all results?