Results 1 to 7 of 7

Thread: [RESOLVED] Displaying results from multiple field query

  1. #1
    Join Date
    Oct 2006
    Ables Springs, Texas

    resolved [RESOLVED] Displaying results from multiple field query

    I am compiling a database of affiliate programs I've joined. Many of those programs have not only their own in-house affiliate program, they also are listed with several affiliate networks. My data entry form and database have fields for those networks as follows:

    On my search form, I wish to search the database for programs by affiliate network to generate a list of programs in that network. The search query seems to be working okay, but I can't seem to get the display right.
    $query = "SELECT * FROM programs WHERE network1 LIKE '$search' OR network2 LIKE '$search' OR network3 LIKE '$search' ORDER BY progname ASC";
    I entered test data for affiliate programs and the corresponding affiliate networks as follows:
    Program Name = affprog1
    network1 = ABC
    networkurl1 = http://www.abc.com/?aff=jg
    network2 = DEF
    networkurl2 = http://www.def.com/?aff=jg
    network3 = XYZ
    networkurl3 = http://www.xyz.com/?aff=jg

    Program Name = affprog2
    network1 = XYZ
    networkurl1 = http://www.xyz.com/?aff=pu
    network2 = DEF
    networkurl2 = http://www.def.com/?aff=pu

    A search for programs belonging to XYZ lists both program names, but I can't get it to list the corresponding network name and network referral url. I've tried several variations, including:
    while ($i < $num) {
              <td><? echo $progname; ?></td>
              <td><? echo $network1 ; ?></td>
              <td><a href="<? echo $networkurl1; ?>"><? echo $networkurl1; ?></a></td>
              <td><? echo $network2 ; ?></td>
              <td><a href="<? echo $networkurl2; ?>"><? echo $networkurl2; ?></a></td>
              <td><? echo $network3 ; ?></td>
              <td><a href="<? echo $networkurl3; ?>"><? echo $networkurl3; ?></a></td>

  2. #2
    Join Date
    May 2010
    Effingham, IL


    Here is an easy way to get everything you need in just a few lines of code.

    $sql = "select * from table"; //your sql statement
    $query = mysql_query($sql, $connection);
    $array = mysql_fetch_assoc($query);

    to display the field from the database simply use the following

    echo $array['field1'];

    This is easier then having to build several variables all the time.
    Ryan Condron
    Freelance Web Developer

  3. #3
    Join Date
    Oct 2006
    Ables Springs, Texas
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

  4. #4
    Join Date
    May 2010
    Effingham, IL


    I have used mysqli for so long I need to look up the reference on the orginal mysql functions. Just an FYI the difference between is that mysql is procedural and mysqli is object oriented. You can use mysqli in procedure code, the mysqli is just updated version of mysql.

    Try this

    $con = mysqli_connect($host, $user, $password, $database);
    $sql = //mysql query
    $query = mysqli_query($con, $sql);
    while ($row = mysqli_fetch_array) {
    echo $row['field1'];

    This will let you have a result of multiple rows. The functional is the same for mysql functions you will need to look up the reference. I just know that the way you had it coded above was lengthy and I was trying to shorten it up for you. Also, if you are just starting out in PHP, I would checkout the Head First book on PHP. I learned the basics from the book and have continued to learn new things.
    Ryan Condron
    Freelance Web Developer

  5. #5
    Join Date
    Oct 2006
    Ables Springs, Texas
    I don't understand how to implement what you are talking about.

    Here is the entire page code I have so far, to better explain what I am attempting to accomplish.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" >
      <meta name="robots" content="noindex, nofollow"/>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    	<link rel="stylesheet" type="text/css" href="http://www.jwgmg.com/styles/style2.css"/>
      <title>Search Results for Affiliate Program Database</title>
    	<base target="_blank" />
    <div style="width: 100%; padding: 1em; text-align: center; margin: auto">
      <p class="center bold lg em">Program by Network Search Results</p>
    $query = "SELECT * FROM programs WHERE netname1 LIKE '$search' OR netname2 LIKE '$search' OR netname3 LIKE '$search' ORDER BY progname ASC";
    $result=mysql_query($query)or die(mysql_error()); 
    	<h1><? echo $search; ?></h1>
    	<table style="border: 1px solid black; text-align: center; margin: auto">
    		<thead style="background-color: #369; color: white">
    			<th>Program Name</th>
    			<th>Referral URL</th>
    while ($i < $num) {
    		<tbody class="left">
    		  <td><? echo $progname; ?></td>
    		  <td><a href="<? echo $neturl; ?>"><? echo $neturl; ?></a></td>
      <table style="margin-left: 12em; border: 2px solid red">
      	<tr><td style="background-color: #369; color: white"><? echo $num; ?></td></tr>

  6. #6
    Join Date
    Aug 2004
    Get rid of the mysql_close(), or else move it to after you are done retrieving all the result rows. (The connection is automatically closed when the script finishes, so normally you don't need to close it explicitly like that unless you expect to have a fair amount of processing in your script once you are done with the connection.)
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  7. #7
    Join Date
    Oct 2006
    Ables Springs, Texas
    Here's the scenario. I have numerous affiliate programs I promote through affiliate networks such as Commission Junction, Cleverbridge and LinkShare. Some of those affiliate programs list with more than one affiliate network.

    I list the individual program in my database as "progname" and the associated affiliate network(s) as "netname1", "netname2" and "netname3" with corresponding referral urls for the associated affiliate program as "netnameurl1", "netnameurl2" and "netnameurl3."

    My desired output is a list of affiliate programs and their matching referral url where the affiliate network name matches the search criteria.

    For example, let's say affiliate program "WebDeveloper.com" is listed with both Commission Junction and LinkShare and my search term is Commission Junction. LinkShare is entered as "netname1" and Commission Junction is entered as "netname2." My desired output would be:

    WebDeveloper.com http://www.cj.com/?id=jwg

    If my search term was LinkShare, the desired output would be:

    WebDeveloper.com http://www.ls.com/?id=gra

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.34606 seconds
  • Memory Usage 2,920KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates