954,162 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Ow damn. it should be:

switch ($type) {
  case 'general': {
  }
  case 'quests': {
  }


Sorry about that.

pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

OMG That put a HUGE smile on my face! It worked!! You are simply amazing pritaeas. Seriously, I am so glad I found you. Ahhh this is sooo awesome! I am sooo happy!

I suppose that is all I need for now. Right? I am pretty sure we covered all the issues and questions I had. Thank you thank you thank you SOOO much!

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Ok, actually. I do need a bit more help. >_>

I didn't think I would but I do. See here's the thing. I know it is easy to use html tags mingled with the php to edit the text for example if you want to bold text that is put there using php it's not hard. But what about for this instance? How do I edit the php to make the data I placed look pretty? Im talking tables, bold, italic, spacing, perhaps even CSS? Right now it is boring old text squashed on the page with no direction.

Please if you could..=)

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Can you give me a specific example ?

pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

Yea Im sorry. I know I'm not clear. I realized the term though of what I am asking. I want to use html tags to make the text from the database look good. Least I think I would use html tags for this. If you used php 'echo' to make text appear I know you can put html tags in the quotes of the text. Anyways, example.

Well, I guess for starters to organize the info perhaps I should put it in a table. Right now the info that shows up is the name of the achievement and the description. Perhaps if I could have all text from 'name' be bold, that might be cool too. I just want to know how I could change the info appearance so that it's not just bunched up and boring looking.

Does that help a little?

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

If you output your name and description like this:

<table>
 <tr>
  <th class="title">name</th>
 </tr>
 <tr>
  <td class="description">description</td>
 </tr>
</table>

you could use a css file to change the layout, e.g. like this:

th.title {
 font-weight: bold;
 color: #000080;
}
td.description {
 color: #800000;
 font-style: italic;
}
pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

As long as I use 'name' and 'description' as they are used in the database then it will know what I am talking about? Also, then how do I instead of having 'name' and 'description' in the small table example that you used, I have the actual title and description that comes from the database show up? I mean, that would mean I would need php inside the table right? I don't understand where I would place it. Anytime I try putting any html mixed in with the php I get an error on my site again.

The php that I am talking about that I want to do this with is the very thing you generated for me before. the 'case' thing, where I tell the description and name to show up. Using that php, where do I place the html? I know how to do the css part, and really I know the html part no problem too, just not mixed with the php. =P

Am I sounding confusing again? I am doing my best to explain what I am trying to do. I'm mainly confused cuz your post only shows html and css, only changing the look of the word 'name' and 'description'. And that's easy, I know how to use html and css together to do that to text. But it's not text directly that I am doing this to, its generated text from a database. So that text doesn't show in my code while I am creating it, so I'm confused as to where to put the html with the php. Do you get what I am saying? Lol cuz I am confusing myself. I hope you understand me, haha.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Something like this:

<table>
<?php
  $db_link = @mysql_connect('localhost', 'username', 'pass') or die(mysql_error());
  @mysql_select_db('wowtahc1_achievements') or die(mysql_error());
 
  $type = $_GET['type'];
  switch ($type) {
    case 'general': {
      $query = 'SELECT * FROM general';
      $result = @mysql_query($query) or die(mysql_error());
      if ($result)
      {
        while ($row = mysql_fetch_assoc($result))
        {
          echo '<tr>';
          echo '<th class="title">' . $row['Name'] . '</th>';
          echo '<td class="description">' . $row['Description'] . '</td>';
          echo '</tr>';
        }
        mysql_free_result($result);
      }
      break;
    }
    case 'quests': {
      $query = 'SELECT * FROM quests';
      $result = @mysql_query($query) or die(mysql_error());
      if ($result)
      {
        while ($row = mysql_fetch_assoc($result))
        {
          echo '<tr>';
          echo '<th class="title">' . $row['Name'] . '</th>';
          echo '<td class="description">' . $row['Description'] . '</td>';
          echo '</tr>';
        }
        mysql_free_result($result);
      }
      break;
    }
  }      
  mysql_close($db_link)
?>
</table>
pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

Erg sorry double post.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Woot woot ok this is good. Let me mess around with this, in the meantime... I do have another question to ask. Hope you don't mind, you have been so good to me. >_>

Alright, you've wonderfully showed me how to pull up data from the entire table, but now how do I do the same thing except for only one specific record on a table? For example, we'll go back to good old http://wowhead.com . You can search their databases that bring up items, but you can also look at one specific item, it creates a page just have we have done with my tables. How do you do that?

Hope that's simple enough, ask if you need a better explanation, I think I did good.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Actually a more personal example..on my site, I have data show of the name and the description of the achievement. Well each name represents a new achievement. I want to be able to take one specific achievement and show only that just as I show only one table from the database right now. For example, on http://www.wowtah.com/achievements.php?type=general the first achievement is "Level 10". I want the user to be able to click on the achievement and just as the tables do, the info changes to whatever I want it to show then. Does that make sense? So that I could have a section that explains how to gain the achievement, granted, this one in particular doesn't need much explaining.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

It would be something like this. I assume you have a column 'id' in your tables that identifies each separate record.

<table>
<?php
  $db_link = @mysql_connect('localhost', 'username', 'pass') or die(mysql_error());
  @mysql_select_db('wowtahc1_achievements') or die(mysql_error());

  $id = isset($_GET['id']) ? $_GET['id'] : 0;
 
  $type = $_GET['type'];
  switch ($type)
  {
    case 'general': {
      if ($id < 1) 
      {
        $query = 'SELECT * FROM general';
        $result = @mysql_query($query) or die(mysql_error());
        if ($result)
        {
          while ($row = mysql_fetch_assoc($result))
          {
            echo '<tr>';
            echo '<th class="title"><a href="achievements.php?type=general&id=' . $row['Id'] . '">' . $row['Name'] . '</a></th>';
            echo '<td class="description">' . $row['Description'] . '</td>';
            echo '</tr>';
          }
          mysql_free_result($result);
        }
      }
      else
      {
        $query = "SELECT * FROM general WHERE id=$id";
        $result = @mysql_query($query) or die(mysql_error());
        if ($result)
        {
          if ($row = mysql_fetch_assoc($result))
          {
            echo '<tr>';
            echo '<th class="title">' . $row['Name'] . '</th>';
            echo '<td class="description">' . $row['Description'] . '</td>';
            echo '</tr>';
          }
          mysql_free_result($result);
        }
      }
      break;
    }
    case 'quests':
    {
      if ($id < 1)
      {
        $query = 'SELECT * FROM quests';
        $result = @mysql_query($query) or die(mysql_error());
        if ($result)
        {
          while ($row = mysql_fetch_assoc($result))
          {
            echo '<tr>';
            echo '<th class="title"><a href="achievements.php?type=quests&id=' . $row['Id'] . '">' . $row['Name'] . '</a></th>';
            echo '<td class="description">' . $row['Description'] . '</td>';
            echo '</tr>';
          }
          mysql_free_result($result);
        }
      }
      else
      {
        $query = "SELECT * FROM quests WHERE id=$id";
        $result = @mysql_query($query) or die(mysql_error());
        if ($result)
        {
          if ($row = mysql_fetch_assoc($result))
          {
            echo '<tr>';
            echo '<th class="title">' . $row['Name'] . '</th>';
            echo '<td class="description">' . $row['Description'] . '</td>';
            echo '</tr>';
          }
          mysql_free_result($result);
        }
      }
      break;
    }
  }      
  mysql_close($db_link)
?>
</table>
pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

Thanks again priteas. :) I am sure that code will work excellently. I just haven't had a chance to have a go with it. Been so busy with school and work I'm finally now replying to you.

So. I do have another question. I added another field to my database, a blob type like you told me to use for pictures. I attached the picture and then I tried having that also show up on my site and it turned everything into mumbo jumbo. Is there some special way you add a blob field? Do I gotta do something different than I do with these varchar type fields? Here is what the part of my code that I edited looked like:

case 'general': {
      $query = 'SELECT * FROM general';
      $result = @mysql_query($query) or die(mysql_error());
      if ($result)
      {
      while ($row = mysql_fetch_assoc($result))
      {
      echo '<br/>' . '<br/>';
      echo $row['Picture'] . '<span class="title">' . $row['Name'] . '</span>';
	  echo '<br/>';
	  echo '<span class="description">' . $row['Description'] . '</span>';
      }
      mysql_free_result($result);
      }
      break;
      }


Whats highlighted in red is what I added. Before that, everything works fine. I even tried replacing 'Name' with 'Picture' just to see if I added the php wrong, but, still same problem. Um, and I guess to make it easier to see what issue is MAYBE the mumbo jumbo that appeared might be useful....

PNG IHDR@@iqmIDATxݛmp[ՙ֕4Wm`b<4i:S~t>v:~`ٲہfg`w3NSR@`j1a#GX*[Eҽx=<9yιM, EHʸ]~)ݵK^L_}| M(5e:rԧ(keyȾs@pxxG~){C=@xפ@8`ȭxi%y\ddx!GF2qFQa+HeT>x@Pѹ5\u) CЕߧg(51x +|؄:ij:gPޠ *T̼v*-$:[

Thats just a small portion of it, but it all looks basically like that, hehe.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

lol dont mind the confused smiley in the middle of the mumbo jumbo, it must have had the correct symbols in the correct spot to make that, hahaha.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

A blob field is just binary data, which in your code gets displayed as text. The most easy way would be to create a separate php page that retrieves your image and displays it. I have an example of this in my original admin panel. I'll need some time to make an example for you.

This thread has a working example, so hopefully you won't need a demo from me: http://www.phpbuilder.com/board/showthread.php?t=10252369

pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

Ok. Um. Yea, that code is a little more confusing looking. Could you maybe explain it a little better than that guy? Cuz I did what he said...but..nothing happened other than I got this on my page:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/wowtahc1/public_html/achievements.php on line 7
">

Line 7 is:

showavatar.php?id=">

now I realize it could be because of $avatardetail cuz that could be something from the guy's database but I dont know the equivilence of it to mine. I did name the .php I put the code in called showavatar.php for the sake of simplicity for now so I know that isn't the issue.

But, I don't think that's the only issue we will run into so, lets also solve some others. Here is the code I put in, (for the sake of showing you my changes trying to get it to function with my database):

<?php
require("tools.php");
if(isset($id))
{
    $filedata = mysql_query("SELECT * FROM general WHERE ID = '".$id."' LIMIT 1");
    header("Content-type: \"".mysql_result($filedata, 0, "filetype")."\"");
// Work out whether we can show or download the attachment:
    $mimetype = explode("/", $row["filetype"]);
    if($mimetype[0] != "Picture")
    {
        header("Content-length: ".mysql_result($filedata, 0, "filesize"));
        header("Content-Disposition: attachment; filename=".mysql_result($filedata, 0, "filename"));
        header("Content-Description: PHP Generated Data");
    }
    echo mysql_result($filedata, 0, "Avatar");
}
?>


I highlighted in red again the changes that I made. I think also I should change "Avatar"? but I dont know to what. Also, I don't see how in this code I can place the image where I want it....

Also, whats tools.php? That code says it requires it and, I can see it on my tabs, it's there, but it's blank.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

You can remove the require(tools), it's something from the other guys code.

You shouldn't have changed "image" into "Picture".

I have a very busy week this week, so I haven't got around to making you a demo.

pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

Oh its no problem. You take your time. I'm in no hurry.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Ok well it's still having a problem with the same line and I still don't understand how I tell it where to put the image.

So whenever you do get a chance to make that demo that would be superb. But like I said before, no rush.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 
pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You