Jump to content

Need help displaying queries and linking.


Zepur

Recommended Posts

Hi!

I am trying to make this site (http://karbotelling.com/TEST/index.php), and because I don't know any PHP I always encounter new problems.

Or rather I cant find the right solutions to the problems.

 

The search field gets values from mysql-query, and outputs it like this:

$querry = ("SELECT * FROM db WHERE ean LIKE '%$trimmed%' OR navn LIKE '%$trimmed%'
ORDER BY navn ASC LIMIT 37");
$numresults=mysql_query($querry);
$numrows=mysql_num_rows($numresults);
if ($numrows == 0)
{
   echo "Kunne dessverre ikke finne noe ved å søke på: " . $trimmed . ".";
}
else
{
// get results
   $bresult = mysql_query($querry) or die("Couldn't execfff query");
   while ($brow= mysql_fetch_array($bresult))
   {
      echo '<div id="mlist" style="width:672; padding-right:5px; align:left;">
      <div id="bulk2" style="padding-bottom:3px">
      <div id="mnavn" class="madd" style="width: 280px">'. $brow['navn'] . '<>
      <div id="mkcal" class="madd" style="width: 62px">'. (float)$brow['kcal'] . '<span id="mspan">kcal</span><>
      <div id="mkarb" class="madd" style="width: 65px">'. (float)$brow['karb'] . '<span id="mspan">g</span><>
      <div id="mprot" class="madd" style="width: 80px">'. (float)$brow['prot'] . '<span id="mspan">g</span><>
      <div id="mfett" class="madd" style="width: 60px">'. (float)$brow['fett'] . '<span id="mspan">g</span><>
      <div id="mean" class="madd" style="width: 125px">'.$brow['ean'].'</span><>
      <><>';
      $lll['navn'][] = $brow['navn'];
   } // end while
}

 

I want to be able to click each .madd-class, to add the values from the divs into a new array. So I can call the array in a separate link.

Its to make a meal, by selecting food you search.

 

I'm sorry if this should be done with javascript /jQuery/ajax and/or something else, but as I said, I have no clue as what to use. And truly sorry if I posted this in the wrong section.

Link to comment
Share on other sites

Well, if it were me and this was a basic form someone could select what they wanted and I wanted to populate an array using their information, I'd simply use a group of checkboxes like so.

 

<input type="checkbox" name="Food[]" value="Carrot"> Carrot </input>
<input type="checkbox" name="Food[]" value="Spinach"> Spinach </input>
<input type="checkbox" name="Food[]" value="Potato"> Potato </input>
<input type="checkbox" name="Food[]" value="Banana"> Banana </input>
<input type="checkbox" name="Food[]" value="Squash"> Squash </input>
<input type="checkbox" name="Food[]" value="Peach"> Peach </input>

 

The [] after the value Food tells the PHP script to store all values into one array called Food. Then you can extract the values as needed however you saw fit.

Link to comment
Share on other sites

Thanks for that, Wolfcry, but wouldn't that be a problem when all my foods (to be chosen) comes from an sql query? And there are ideally 2000+ food items to search from.

 

And I really want the entire field assigned to each search-hit, to be clickable. (the ones on the right http://karbotelling.com/TEST/index.php?q=703&Submit=S%C3%B8k. The site does not look good in IE btw, but thats my dont-care-about-IE-users-css)

 

 

If what I'm asking is too complicated with PHP, is there an easier way with another language?

Link to comment
Share on other sites

I see, I thought you were trying to store inputted data as one array much one would do in a form.

 

the site does not look good in IE btw, but thats my dont-care-about-IE-users-css)

 

That's a really bad practice to get into, especially since you will be alienating a huge user base and there's nothing wrong with having a different personal preference over another.

 

I personally run FF, but If I were running IE and came across a site that intentionally directed me to a crappy page because of my browser, I'd never go back nor would I ever refer your site to those I know with the same interests..

Link to comment
Share on other sites

It's only intentionally till I get the site working :)

Cant alienating the majority of users.

Good to know ;)

 

If you want it to be immediate, as in as soon as the user clicks a queried link, you will need client-side scripting to do so (like JavaScript etc..) because PHP is a server side language.

Link to comment
Share on other sites

If you want it to be immediate, as in as soon as the user clicks a queried link, you will need client-side scripting to do so (like JavaScript etc..) because PHP is a server side language.

I think you're right, I'll ask the guys on the js-subforum.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.