Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do a join on this code AND how to retrieve data within the PHP form
    primarykey
    data
    text
    <p>I'm unable to figure out how to implement a join in this code. Also a second issue is that I want to use <code>'Charity No: '.$don['charity_id'].'&lt;br/&gt;'.</code> in the mysql_query <code>("SELECT * FROM charity where id='?????????'")</code></p> <p>What the code does now is it retrieves all this data which is fine, but I want charity_id[FK](which is in the donation table) as charityname(from the charity table) instead, and im sure this is done using a join but can't figure out how to do this in my code. The second issue is that I want to create a rating system that rates the charity (based on the charity number) the data is literraly a few lines above but I can't figure this out either. </p> <p>My code is:</p> <pre><code>&lt;?php if (!isset($_POST['do']) || !isset($_POST['id']) || !$_POST['id']) exit; require_once 'connection.php'; $don=mysql_fetch_assoc( mysql_query('SELECT * FROM donation WHERE id="'.mysql_real_escape_string($_POST['id'],$con).'"',$con)); if ($don===false || !$don['id']) print '&lt;h3&gt;Donation id #'.$_POST['id'].' does not exist!&lt;/h3&gt;'; else { print '&lt;h3&gt;Information about donation id #'.$_POST['id'].'&lt;/h3&gt;'. 'Donor ID: '.$don['donor_id'].'&lt;br/&gt;'. 'Charity No: '.$don['charity_id'].'&lt;br/&gt;'. 'Date &amp; Time: '.$don['TransactionTime'].'&lt;br/&gt;'. 'Donation Amount: £ '.number_format($don['D_Amount'],2).'&lt;br/&gt;'. } $find_data = mysql_query("SELECT * FROM charity where id='?????????'"); while($row = mysql_fetch_assoc($find_data)) { $id = $row['id']; $C_Name = $row['CharityName']; $C_Desc = $row['CharityDescription']; $Hits = $row['Hits']; $Ranking = $row['Ranking']; echo " &lt;form action='rate.php' method='POST'&gt; $C_Name: &lt;select name='Ranking'&gt; &lt;option&gt;1&lt;/option&gt; &lt;option&gt;2&lt;/option&gt; &lt;option&gt;3&lt;/option&gt; &lt;option&gt;4&lt;/option&gt; &lt;option&gt;5&lt;/option&gt; &lt;/select&gt; &lt;input type='hidden' value=$id name='ID'&gt; &lt;input type='submit' value='Rate'&gt;; &lt;/form&gt; "; } </code></pre> <p>The JOIN I tried now is:</p> <pre><code>$don=mysql_fetch_assoc( mysql_query('SELECT * FROM donation As D JOIN charity as C ON d.charity_id=C.id WHERE id="'.mysql_real_escape_string($_POST['id'],$con).'"',$con)); </code></pre> <p>But now luck.</p> <p>Any help given would be highly appreciated, Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload