473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

i'm trying to pass html value to function

i've been on it for 2 days. can someone help

search.php
************************************************** **************
<form method="post" action="search.php">
<select id="name" name="name">
<option value="entertainment">Entertainment</option>
<option value="romance">Romance</option>
</select>
</br>
<input class="w3-input" type="text" id="location" name="location" placeholder="Location">
</br>
<input type="text" id="city" name="city" placeholder="City">
</br>
<select id="state" name="state">
<option value="newyork">new york</option>
<option value="texas">texas</option>
<option value="london">london</option>
</select>
</br>
<input type="submit" name="submit" value="Search">
</form>
************************************************** **************


i want to pass the value to getPublishedPosts()


public_functions.php
************************************************** ****************
// form variables from users

$name = "";
$type = "";
$area = "";
$city = "";
$state = "";



/* - - - - - - - - - -
- Admin users actions
- - - - - - - - - - -*/
// if user clicks the search button
if (isset($_POST['submit'])) {
getPublishedPosts($_POST);
}


/* * * * * * * * * * * * * * *
* Returns all published posts
* * * * * * * * * * * * * * */



function getPublishedPosts($request_values) {
global $conn, $name, $type, $area, $city, $state;
$name = $request_values['name'];
$type = $request_values['type'];
$area = $request_values['area'];
$city = $request_values['city'];
$state = $request_values['state'];


$sql = "SELECT id, area, city, file_name FROM search WHERE name LIKE '%".$name."%' AND type LIKE '%".$type."%' AND area LIKE '%".$area."%' AND city LIKE '%".$city."%' AND state LIKE '%".$state."%'";
$result = mysqli_query($conn, $sql);
// fetch all posts as an associative array called $posts
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);

$final_posts = array();
foreach ($posts as $post) {
$post['topic'] = getPostTopic($post['id']);
array_push($final_posts, $post);
}
return $final_posts;
}
************************************************** **************************



to display the result gotten from database on index.php

index.php
************************************************** ***************

<?php foreach ($posts as $post): ?>
<a href="single_post.php?post-slug=<?php echo $post['slug']; ?>">
<div class="w3-third">
<div class="w3-card w3-btn">
<img src="<?php echo BASE_URL . '/static/images/' . $post['image']; ?>" class="post_image" alt="">
<h5><?php echo $post['area'] ?><h5/>
<h3><?php echo $post['city'] ?><h3/>
</div>
</div>
</a>
<?php endforeach ?>


************************************************** **********
Sep 20 '18 #1
0 374

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: wilson | last post by:
Dear all, In this time, I want to pass array to function. What should I declare the parameter in the function?i int array or int array? Which one is correct? ...
4
by: jrefactors | last post by:
In the following program, are parameters s in function reverse() and x in function count() both pass by value? How come value k is not changed, but value str has changed? Please advise....
9
by: Alvin Bruney | last post by:
The more knowledgable I get about this .net world, the more questions I have. ..NET uses pass by reference for all objects....uhhh I mean pass by value. (Couldn't resist this jab) Consider a...
2
by: Bob Lehmann | last post by:
I have a web form (Form1) that I would like to pass to a function, iterate through it, and retrieve the values of the input elements. I am able to retrieve the element IDs (function below), but...
13
by: pauldepstein | last post by:
My texts give plenty of examples where passing by reference is necessary. For instance, the famous swap example. However, I've never seen an example where passing a variable by value is...
14
by: xdevel | last post by:
Hi, I need your help because I don't understand very well this: in C arguments are passed by-value. The function parameters get a copy of the argument values. But if I pass a pointer what really...
3
by: Steve Kershaw | last post by:
Hi, I need to pass a value from a hidden input: <input id="hiddentxtWidth" type="hidden" value="1065" /> to a JavaScript function. I've tried the following: <script type="text/javascript" >...
10
by: somenath | last post by:
Hi All, I was trying to understand the pass by value mechanism in c. To understand it I wrote a Small code as mentioned bellow. #include<stdio.h> #include<stdlib.h> #include<string.h> void...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
3
by: maheswaran | last post by:
Hi all, Its is an simple question, but for me it takes more than 2 hours. Just i want to pass the value using java script function See this <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.